SELECT a.index_id ,
b.name ,
a.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(DB_ID(), OBJECT_ID(''),
NULL, NULL, NULL) as a
JOIN sys.indexes as b ON a.object_id = b.object_id
AND b.index_id = a.index_id
当 5%<avg_fragmentation_in_percent<30% , 可以使用 alter index reorganize 重新组织索引。
avg_fragmentation_in_percent>30 ,应当使用 alter index rebuild 语句重新生成索引。