SQL语句实现查询Index使用状况
作者:junjie 时间:2024-01-24 13:44:46
SELECT
sch.name + '.' + t.name AS [Table Name],
i.name AS[Index Name],
i.type_desc,
ISNULL(user_updates,0) AS [Total Writes],
ISNULL(user_seeks +user_scans + user_lookups,0) AS [Total Reads],
s.last_user_seek,
s.last_user_scan ,
s.last_user_lookup,
ISNULL(user_updates,0) - ISNULL((user_seeks+ user_scans +user_lookups),0)AS [Difference],
p.reserved_page_count * 8.0 / 1024 as SpaceInMB
FROM sys.indexes AS i WITH (NOLOCK)
LEFT OUTERJOIN sys.dm_db_index_usage_statsAS s WITH (NOLOCK) ON s.object_id = i.object_id AND i.index_id = s.index_id AND s.database_id=db_id() AND objectproperty(s.object_id,'IsUserTable') = 1
INNER JOIN sys.tables AS t WITH (NOLOCK) ON i.object_id = t.object_id
INNER JOIN sys.schemas AS sch WITH (NOLOCK) ON t.schema_id = sch.schema_id
LEFT OUTERJOIN sys.dm_db_partition_stats AS p WITH (NOLOCK) ON i.index_id = p.index_id and i.object_id = p.object_id
WHERE (1=1)
--AND ISNULL(user_updates,0) >=ISNULL((user_seeks + user_scans + user_lookups),0) --shows all indexesincluding those that have not been used
--AND ISNULL(user_updates,0) -ISNULL((user_seeks + user_scans + user_lookups),0)>0 --only shows thoseindexes which have been used
--AND i.index_id > 1 -- Only non-first indexes (I.E.non-primary key)
--AND i.is_primary_key<>1 -- Only those that are not defined asa Primary Key)
--AND i.is_unique_constraint<>1-- Only those that are not classed as "UniqueConstraints".
ORDER BY [Table Name],[index name]
标签:SQL,语句,查询,Index,使用
0
投稿
猜你喜欢
python中的装饰器详解
2022-08-14 04:32:05
php之app消息推送案例教程
2023-06-15 00:42:02
对DataFrame数据中的重复行,利用groupby累加合并的方法详解
2023-09-06 03:01:19
如何理解python中数字列表
2023-01-30 13:29:09
python可视化实现KNN算法
2022-07-23 11:17:03
python+requests+pytest接口自动化的实现示例
2022-11-01 06:12:27
vant中的toast轻提示实现代码
2024-04-26 17:38:53
OpenCV 轮廓检测的实现方法
2023-06-16 01:40:48
Python中if语句的基本格式实例代码
2023-12-02 14:31:20
ACCESS数据库的压缩,备份,还原,下载,删除的实现
2024-01-18 16:16:26
爬虫Python验证码识别入门
2021-01-31 15:31:19
python实现将json多行数据传入到mysql中使用
2022-12-28 06:41:51
通过SQL Server的位运算功能巧妙解决多选查询方法
2024-01-22 01:21:26
分享PHP header函数使用教程
2023-09-04 12:07:14
python操作excel之xlwt与xlrd
2023-02-11 08:05:52
ASP写的不错的"数字分页"涵数
2008-10-19 17:21:00
基于Python实现RLE格式分割标注文件的格式转换
2022-10-22 08:41:12
ASP错误大全
2009-05-26 15:45:00
Python 切分数组实例解析
2022-04-15 02:45:05
在Windows服务器下用Apache和mod_wsgi配置Python应用的教程
2021-10-28 22:36:17