--External debris rate >10 indicates the occurrence of external debris rate;
--Internal fragmentation rate <75 indicates internal fragmentation rate occurs
SELECT object_name (dt.object_id) Table name,
Si.name index Name,
External fragment Rate =case when
Dt.avg_fragmentation_in_percent>10 THEN ' High fragment rate '
ELSE ' normal '
End
,
Internal fragmentation rate = case when dt.avg_page_space_used_in_percent <75 THEN ' normal '
ELSE ' High fragment rate '
End
From (SELECT object_id,
INDEX_ID,
Avg_fragmentation_in_percent,
Avg_page_space_used_in_percent
From Sys.dm_db_index_physical_stats (db_id (' jinriairv2 '), NULL, NULL,
NULL, ' DETAILED ')
WHERE index_id <> 0
) as DT
INNER JOIN sys.indexes si on si.object_id = dt.object_id
and si.index_id = dt.index_id
and Dt.avg_fragmentation_in_percent >10
and Dt.avg_page_space_used_in_percent <75
ORDER BY Avg_fragmentation_in_percent DESC
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/SQLServer/