Showing posts with label Query to Index Fragmentation. Show all posts
Showing posts with label Query to Index Fragmentation. Show all posts

Tuesday, November 7, 2017

Query to Index Fragmentation (Detailed)

SELECT  OBJECT_NAME(i.OBJECT_ID) AS TableName,
i.name AS IndexName,
indexstats.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL , NULL, 'DETAILED') indexstats
INNER JOIN sys.indexes i ON i.OBJECT_ID = indexstats.OBJECT_ID
WHERE avg_fragmentation_in_percent > 10.0 AND i.index_id > 0
order by indexstats.avg_fragmentation_in_percent desc