Tuesday, November 12, 2013

Fragmentation of Views

SELECT DB_NAME() [database], OBJECT_NAME(a.object_id) [table], idx.[name], a.object_id, a.index_id, a.index_type_desc, a.alloc_unit_type_desc, avg_fragmentation_in_percent, a.page_count
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'SAMPLED') a
JOIN sys.indexes idx ON idx.object_id = a.object_id AND idx.index_id = a.index_id
WHERE page_count > 1000
AND avg_fragmentation_in_percent > 10.0
ORDER BY avg_fragmentation_in_percent DESC

No comments:

Post a Comment