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 interestedCREATE PROCEDURE dbo.sproc_SHOWCONTIG ASCREATE 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 orderINSERT INTO #Tables (TableName) SELECT NAME FROM Shire2.dbo.sysobjects where type = 'U' order by NAMEDECLARE @Current as SYSNAME --DECLARE @SQL as nvarchar(4000)DECLARE @ID intWHILE 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 ENDGO
A sarcasm detector, what a great idea.