索引使用率

-------------索引使用率
select distinct 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('DBNAME')   ---改成要查看的数据库  
and object_name(a.object_id) not like 'sys%'  
order by user_seeks,user_scans,object_name(a.object_id)-----判断是否需要更新索引统计信息  



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)



转载于:https://www.cnblogs.com/baozhu/p/8093827.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值