Find Table Fragmentation
-
Posted on May 31, 2009 by Derek Dieter
[cc lang=”sql”] DECLARE @Database VARCHAR(255) DECLARE @TableName VARCHAR(255) DECLARE @IndexName VARCHAR(255) SET @Database = ‘SQLServerPlanet’ SET @TableName = ‘Users’ SET @IndexName = NULL SELECT avg_fragmentation_in_percent ,page_count FROM sys.dm_db_index_physical_stats ( DB_ID(@Database) ,OBJECT_ID(@TableName) ,OBJECT_ID(@IndexName) ,NULL ,NULL ) [/cc] Or you can still do it the old fashioned way. Just substitute the name of the table or index below. It should not be in quotes. [cc lang=”sql”][/cc] –Just the table DBCC SHOWCONTIG (tablename) –Table with the index DBCC SHOWCONTIG (tablename, indexname) –Do not block anything (run during prod hours) DBCC SHOWCONTIG (tablename, indexname) WITH FAST –(2005) [cc lang=”sql”][/cc]
Continue reading ...