笔记81 查看SQL索引使用情况
1 --查看SQL索引使用情况
2 use dbName --要查看的数据库
3
4 select db_name(database_id) as N'数据库名称',
5 object_name(a.object_id) as N'表名',
6 b.name N'索引名称',
7 user_seeks N'用户索引查找次数',
8 user_scans N'用户索引扫描次数',
9 last_user_seek N'最后查找时间',
10 last_user_scan N'最后扫描时间',
11 rows as N'表中的行数'
12 from sys.dm_db_index_usage_stats a join
13 sys.indexes b
14 on a.index_id = b.index_id
15 and a.object_id = b.object_id
16 join sysindexes c
17 on c.id = b.object_id
18 where database_id=db_id('DBName') ---改成要查看的数据库
19 and object_name(a.object_id) not like 'sys%'
20 order by user_seeks,user_scans,object_name(a.object_id)