在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')