SQL Server 2005的索引密度和碎片信息

SELECT i.nameASindexname,
o.nameAStablename,
s.nameASschemaname,
f.index_type_descASindextype,
f.avg_page_space_used_in_percentASindexdensity,
f.avg_fragmentation_in_percentASindexfragmentation,
f.page_countASpages
FROMsys.dm_db_index_physical_stats(DB_ID(),NULL,NULL,NULL, 'SAMPLED') f
INNERJOINsys.objects oONo.object_id = f.object_id
INNERJOINsys.schemas sONo.schema_id = s.schema_id
INNERJOINsys.indexes iONf.object_id = i.object_id AND f.index_id = i.index_id
WHEREpage_count > 50ANDf.index_id > 0
ORDERBYo.name, i.index_id


LIMITED | SAMPLED | DETAILED | NULL | DEFAULT
这些模式影响了如何收集碎片数据。LIMITED模式扫描堆所有的页,但对于索引,则只扫描叶级上面的父级别页。SAMPLED收集在堆或索引中1%采样率的数据。DETAILED模式扫描所有页(堆或索引)。DETAILED是执行最慢的,但也是最精确的选项。指定NULL或DEFAULT的效果与LIMITED模式的相同

你可能感兴趣的:(sql,SQL Server,F#)