SQL語句實現(xiàn)查詢Index使用狀況
更新時間:2015年07月07日 10:52:35 投稿:junjie
這篇文章主要介紹了SQL語句實現(xiàn)查詢Index使用狀況,本文直接給出SQL腳本代碼,需要的朋友可以參考下
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]
相關(guān)文章
mssql中得到當(dāng)天數(shù)據(jù)的語句
mssql中得到當(dāng)天數(shù)據(jù)的語句...2007-08-08
SQL Server中的文本函數(shù)和圖像函數(shù)介紹
這篇文章介紹了SQL Server中的文本函數(shù)和圖像函數(shù),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05
sqlserver 2000數(shù)據(jù)庫同步 同步兩個SQLServer數(shù)據(jù)庫的內(nèi)容
程序代碼可以有版本管理CVS進行同步管理,可是數(shù)據(jù)庫同步就非常麻煩,只能自己改了一個后再去改另一個,如果忘記了更改另一個經(jīng)常造成兩個數(shù)據(jù)庫的結(jié)構(gòu)或內(nèi)容上不一致.2010-05-05
Sql Server數(shù)據(jù)庫實現(xiàn)表中字段的列加密
本文主要介紹了Sql Server數(shù)據(jù)庫實現(xiàn)表中字段的列加密,主要包括利用證書對數(shù)據(jù)進行加密和解密,利用非對稱密鑰對數(shù)據(jù)進行加密和解密,利用對稱密鑰對數(shù)據(jù)進行加密和解密,感興趣的可以了解一下2023-10-10
SQL Server中Check約束的學(xué)習(xí)教程
這篇文章主要介紹了SQL Server中Check約束的學(xué)習(xí)教程,包括對啟用Check約束來提升性能的介紹,需要的朋友可以參考下2015-12-12
SQL Server中Table字典數(shù)據(jù)的查詢SQL示例代碼
這篇文章主要給大家介紹了關(guān)于SQL Server中Table字典數(shù)據(jù)的查詢SQL的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-10-10

