MsSqlServer 查看数据库索引的使用情况

2021/9/2 19:06:37

本文主要是介绍MsSqlServer 查看数据库索引的使用情况,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

--查看数据库索引的使用情况
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('db1') ---改成要查看的数据库
and object_name(a.object_id) not like 'sys%'
and object_name(a.object_id)='table_V2'  ---改成要查看的表
order by user_seeks,user_scans,object_name(a.object_id)

--清空查询缓存
DBCC freeproccache

-- 查看sql执行计划
SELECT * FROM V2 --表名

SELECT cacheobjtype ,
objtype ,
usecounts ,
sql
FROM sys.syscacheobjects
WHERE sql NOT LIKE '%cach%'
AND sql NOT LIKE '"sys."'
AND cacheobjtype LIKE '%Plan%'

--查看表,索引结构
sp_help 'V2'



这篇关于MsSqlServer 查看数据库索引的使用情况的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程