首页 > 代码库 > 索引碎片统计

索引碎片统计

SELECT index_type_desc,alloc_unit_type_desc,avg_fragmentation_in_percent,fragment_count,avg_fragment_size_in_pages,page_count,record_count,avg_page_space_used_in_percent
FROM sys.dm_db_index_physical_stats(DB_ID(‘advanced6‘),OBJECT_ID(‘Table_2‘),NULL,NULL,‘Sampled‘)

技术分享

 

当avg_fragmentation_in_percent 大于40%时,往往需要整理与重建索引,方法如下:
ALTER INDEX PK_Table_2 ON Table_2 REBUILD

索引碎片统计