多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 數據庫 > Sqlserver > SQL Server 查找未使用的非聚集索引和表

SQL Server 查找未使用的非聚集索引和表

來源:程序員人生   發布時間:2013-11-01 21:44:10 閱讀次數:2865次

查找未使用的非聚集索引和未使用的表.

DMV:sys.dm_db_index_usage_stats
The counters are initialized to empty whenever the SQL Server (MSSQLSERVER) service is started. In addition, whenever a database is detached or is shut down (for example, because AUTO_CLOSE is set to ON), all rows associated with the database are removed.

--查找未使用的非聚集索引(排除聚集索引和堆表)
--This returns all the noclustered indexes that have not been used for any requests by users
--or the system from the time SQL Server is started.
-- nzperfect
select tablename,indexname,'drop index '+tablename+'.'+indexname as dropIndexCommand
from
(
select object_name(i.object_id) as tablename, i.name as indexname
from sys.indexes i
left outer join sys.dm_db_index_usage_stats s
on s.object_id = i.object_id and s.index_id = i.index_id
and s.database_id = db_id()
where objectproperty(i.object_id, 'IsUserTable') = 1
and objectproperty(i.object_id,'IsMSShipped')=0
and i.index_id > 1 -- 0 indicates the heap 1 indicates the clustered index
and i.is_primary_key = 0 -- 1 indicates the primary key
and s.object_id is null
union all
select object_name(i.object_id) as tablename, i.name as indexname
from sys.indexes i
inner join sys.dm_db_index_usage_stats s
on s.object_id = i.object_id and s.index_id = i.index_id
and s.database_id = db_id()
where objectproperty(i.object_id, 'IsUserTable') = 1
and objectproperty(i.object_id,'IsMSShipped')=0
and i.index_id > 1 -- 0 indicates the heap 1 indicates the clustered index
and i.is_primary_key = 0 -- 1 indicates the primary key
and (s.user_seeks + s.user_scans + s.user_lookups)=0
)a

--查找未使用的表
--This returns all the table that have not been used for any requests by users
--or the system from the time SQL Server is started.
--nzperfect
select object_name(i.object_id) as tablename, i.name as clusteredindexname,
case when i.index_id=0 then 'Heap Table'
when i.index_id=1 then 'Clustered Table' end as TableType
from sys.indexes i
left outer join sys.dm_db_index_usage_stats s
on s.object_id = i.object_id and s.index_id = i.index_id
and s.database_id = db_id()
where objectproperty(i.object_id, 'IsUserTable') = 1
and objectproperty(i.object_id,'IsMSShipped')=0
and i.index_id in (0,1) -- 0 indicates the heap 1 indicates the clustered index
and s.object_id is null

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 最新中文字幕日本 | 伊人欧美在线 | 日本一级级特黄特色大片 | 国产精品一区二区免费 | 高清日本一级特黄aa大片 | www黄视频| 日本高清一道本 | 亚洲黄色在线观看视频 | 久久天天躁夜夜躁狠狠85台湾 | 韩日一区二区三区 | 国产精品久久久久影视不卡 | 成年人小视频在线观看 | 国产一区精品 | 亚洲图片欧美 | 亚洲图片小说区 | 国产精品爱久久久久久久 | 伊人亚洲综合网成人 | 性欧美乱又伦 | 美女享受黑人的巨茎 | 羞羞免费网站 | 日本乱人伦片中文字幕三区 | 最新中文字幕乱码在线 | 中国高清色视频www 中国国产成人精品久久 | 丁香网五月| 日韩精品网站 | 香蕉国产成版人视频在线观看 | 日本女人一级片 | 国产精品久久久久久 | 中文字幕网站在线观看 | 成人免费淫片免费观看 | 久久天天躁狠狠躁夜夜 | 图片专区亚洲 欧美 另类 | 国产高清在线精品免费不卡 | 五月婷婷综合在线 | 久久精品亚洲一区二区 | 另类亚洲孕妇分娩网址 | 24小时免费观看www日本 | 最近中文字幕mv免费高清视频免费 | 在线日韩观看 | 日韩精品一区二区三区毛片 | 天天躁夜夜燥2021 |