1. 统计没用使用过的索引:
如果有聚集索引,则表为B-Tree
如果没有聚集索引,则表为Heap
select
b.name ,a.name ,a.index_id,c.
object_id
from
sys.indexes a
inner join sys.tables b
on a. object_id = b. object_id
and a.name is not null
left join sys.dm_db_index_usage_stats c
on a. object_id = c. object_id and c.database_id = db_id ()
and c.index_id <> 0 -- 堆
where c. object_id is null
inner join sys.tables b
on a. object_id = b. object_id
and a.name is not null
left join sys.dm_db_index_usage_stats c
on a. object_id = c. object_id and c.database_id = db_id ()
and c.index_id <> 0 -- 堆
where c. object_id is null
本文提供了一种SQL查询方法,用于找出数据库中未被使用的索引。通过联接多个系统表和视图,可以有效地识别出那些从未被查询利用的索引,帮助优化数据库性能。

被折叠的 条评论
为什么被折叠?



