Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Script Library
 Show Contig SQL Server 7

Author  Topic 

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2005-05-20 : 08:14:25
After some of the recent discussions on Index fragmentation I've produced this code to do a show contig on all the tables in a specific database on SQL Server 7.

It can probably be made more generic for those interested


CREATE PROCEDURE dbo.sproc_SHOWCONTIG 
AS
CREATE TABLE #Tables
(
Table_ID INT IDENTITY(1, 1) NOT NULL,
TableName SYSNAME NOT NULL
)

-- Put all the (user) table names into at temporary table - in order so that the output is in order
INSERT INTO #Tables (TableName) SELECT NAME FROM Shire2.dbo.sysobjects where type = 'U' order by NAME

DECLARE @Current as SYSNAME
--DECLARE @SQL as nvarchar(4000)
DECLARE @ID int


WHILE EXISTS (SELECT 1 FROM #Tables)
BEGIN
--print 'in BEGIN'
-- get current table into a variable name
SET @CURRENT = (SELECT TOP 1 TableName FROM #Tables)
--print 'Current = ' + @current
SET @ID = OBJECT_ID(@CURRENT)
DBCC SHOWCONTIG (@ID)
-- EXEC sp_executesql @SQL
DELETE FROM #Tables WHERE TableName = @CURRENT
END



GO


A sarcasm detector, what a great idea.

Kristen
Test

22859 Posts

Posted - 2005-05-26 : 01:54:24
I use one which reindexes/defrags based on whether the CONTIG is over/under 80% based on:

http://www.sql-server-performance.com/forum/topic.asp?TOPIC_ID=444

Kristen
Go to Top of Page

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2005-05-26 : 02:54:57
EEEK!! Cursors! Spawn of the DEVIL I tell you

Cheers Kristen

steve

A sarcasm detector, what a great idea.
Go to Top of Page
   

- Advertisement -