insert_of_script_showcontig

Script to analyze all populated tables for internal fragmentation.

It would be a good idea to update usages prior to running this script as it depends on the row count in sysindexes to determine which tables to analyze. If you run DBCC SHOWCONTIG on an empty table, you will get an error.


DELETE scripts WHERE name = 'script_showcontig'
GO
INSERT scripts 
VALUES('script_showcontig','DECLARE @id int')
INSERT scripts 
VALUES('script_showcontig','SET NOCOUNT ON')
INSERT scripts 
VALUES('script_showcontig','SELECT @id = MIN(id) FROM sysobjects')
INSERT scripts 
VALUES('script_showcontig','WHERE id > 99')
INSERT scripts 
VALUES('script_showcontig','AND id IN (SELECT id FROM sysindexes')
INSERT scripts 
VALUES('script_showcontig','           WHERE rows > 0)')
INSERT scripts 
VALUES('script_showcontig','WHILE @id IS NOT NULL')
INSERT scripts 
VALUES('script_showcontig','  BEGIN')
INSERT scripts 
VALUES('script_showcontig','    DBCC SHOWCONTIG(@id)')
INSERT scripts 
VALUES('script_showcontig','    SELECT @id = MIN(id) FROM sysobjects')
INSERT scripts 
VALUES('script_showcontig','    WHERE id > @id')
INSERT scripts 
VALUES('script_showcontig','    AND id IN (SELECT id FROM sysindexes')
INSERT scripts 
VALUES('script_showcontig','               WHERE rows > 0)') 
INSERT scripts 
VALUES('script_showcontig','  END')