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

sql server 调优----索引未使用

时间:2015-09-23 18:35:10      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:


SELECT TOP 1000
o.name AS 表名
, i.name AS 索引名
, i.index_id AS 索引id
, dm_ius.user_seeks AS 搜索次数
, dm_ius.user_scans AS 扫描次数
, dm_ius.user_lookups AS 查找次数
, dm_ius.user_updates AS 更新次数
, p.TableRows as 表行数
, ‘DROP INDEX ‘ + QUOTENAME(i.name)
+ ‘ ON ‘ + QUOTENAME(s.name) + ‘.‘ + QUOTENAME(OBJECT_NAME(dm_ius.OBJECT_ID)) AS ‘删除语句‘
FROM sys.dm_db_index_usage_stats dm_ius
INNER JOIN sys.indexes i ON i.index_id = dm_ius.index_id AND dm_ius.OBJECT_ID = i.OBJECT_ID
INNER JOIN sys.objects o ON dm_ius.OBJECT_ID = o.OBJECT_ID
INNER JOIN sys.schemas s ON o.schema_id = s.schema_id
INNER JOIN (SELECT SUM(p.rows) TableRows, p.index_id, p.OBJECT_ID
FROM sys.partitions p GROUP BY p.index_id, p.OBJECT_ID) p
ON p.index_id = dm_ius.index_id AND dm_ius.OBJECT_ID = p.OBJECT_ID
WHERE OBJECTPROPERTY(dm_ius.OBJECT_ID,‘IsUserTable‘) = 1
AND dm_ius.database_id = DB_ID()
AND i.type_desc = ‘nonclustered‘
AND i.is_primary_key = 0
AND i.is_unique_constraint = 0
and o.name=‘SMT_FCT‘ --根据实际修改表名
ORDER BY (dm_ius.user_seeks + dm_ius.user_scans + dm_ius.user_lookups) ASC

sql server 调优----索引未使用

标签:

原文地址:http://www.cnblogs.com/yuannfei19841121/p/4832667.html

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