在SQL2005中添加了新的功能用来查询索引的碎片状况。以下语句能够查询指定表的索引碎片状况。sql
- --phonesale 数据库名, tbldiallog表名
- SELECT SI.NAME,
- DDI.avg_fragmentation_in_percent
- FROM sys.indexes AS SI, sys.dm_db_index_physical_stats(DB_ID('phonesale'),OBJECT_ID('tblDiallog'),NULL,NULL,'LIMITED') AS DDI
- WHERE SI.INDEX_ID = DDI.INDEX_ID AND SI.OBJECT_ID = OBJECT_ID('TBLDIALLOG')