码迷,mamicode.com
首页 > 数据库 > 详细

SQL Server 查询索引的使用情况

时间:2015-10-20 17:51:59      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:

SELECT OBJECT_NAME(s.[object_id]) AS [Table Name] ,
i.name AS [Index Name] ,
i.index_id ,
user_updates AS [Total Writes] ,
user_seeks + user_scans + user_lookups AS [Total Reads] ,
user_updates - ( user_seeks + user_scans + user_lookups )
AS [Difference]
FROM sys.dm_db_index_usage_stats AS s WITH ( NOLOCK )
INNER JOIN sys.indexes AS i WITH ( NOLOCK )
ON s.[object_id] = i.[object_id]
AND i.index_id = s.index_id
WHERE OBJECTPROPERTY(s.[object_id], ‘IsUserTable‘) = 1
AND s.database_id = DB_ID()
AND user_updates > ( user_seeks + user_scans + user_lookups )
AND i.index_id > 1 --and OBJECT_NAME(s.[object_id])=‘Lot‘
ORDER BY [Difference] DESC ,
[Total Writes] DESC ,
[Total Reads] ASC ;

--执行结果

技术分享

--结果描述,只介绍倒数2,3列, Total Write 与 Total Reads

如果 Total Reads 等于 0,说明索引没起作用,建议删除当前索引

SQL Server 查询索引的使用情况

标签:

原文地址:http://www.cnblogs.com/dong-1984dd/p/4895400.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!