—在優化查詢SQL語句,查看索引使用情況SQL語句:
select db_name(database_id) as N'數據庫名稱',
object_name(a.object_id) as N'表名',
b.name N'索引名稱',
user_seeks N'用戶索引查找次數',
user_scans N'用戶索引掃描次數',
last_user_seek N'最后查找時間',
last_user_scan N'最后掃描時間',
rows as N'表中的行數'
from sys.dm_db_index_usage_stats a join
sys.indexes b
on a.index_id = b.index_id
and a.object_id = b.object_id
join sysindexes c
on c.id = b.object_id
where database_id=db_id('數據庫名') --指定數據庫
and object_name(a.object_id) not like 'sys%'
and object_name(a.object_id) like '表名' --指定索引表
and b.name like '索引名' --指定索引名稱 可以先使用 sp_help '你的表名' 查看表的結構和所有的索引信息
order by user_seeks,user_scans,object_name(a.object_id)
—在優化查詢SQL語句,查看索引使用情況SQL語句:
select db_name(database_id) as N'數據庫名稱',
object_name(a.object_id) as N'表名',
b.name N'索引名稱',
user_seeks N'用戶索引查找次數',
user_scans N'用戶索引掃描次數',
last_user_seek N'最后查找時間',
last_user_scan N'最后掃描時間',
rows as N'表中的行數'
from sys.dm_db_index_usage_stats a join
sys.indexes b
on a.index_id = b.index_id
and a.object_id = b.object_id
join sysindexes c
on c.id = b.object_id
where database_id=db_id('數據庫名') --指定數據庫
and object_name(a.object_id) not like 'sys%'
and object_name(a.object_id) like '表名' --指定索引表
and b.name like '索引名' --指定索引名稱 可以先使用 sp_help '你的表名' 查看表的結構和所有的索引信息
order by user_seeks,user_scans,object_name(a.object_id)
"/>