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.