Joe's Knowledge Base - a collection of various tips-n-tricks for SQL Server.
Note: best effort to site sources where applicable, otherwise curated from BOL/MSDN or self-created.
Tuesday, January 8, 2013
SQL Server Find Table Fragmentation
SELECT db.Name
, OBJECT_NAME(s.OBJECT_ID)
, s.avg_fragmentation_in_percent Perc
FROM sys.dm_db_index_physical_stats (NULL, NULL, NULL, NULL, NULL) s
JOIN MASTER.DBO.SYSDATABASES db
ON s.database_id = db.dbID
WHERE s.database_id = 7
ORDER BY Perc Desc
No comments:
Post a Comment