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 sy ...
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 語句重新生成索引。