SQL Statement Implementation Query index use status _mssql

Source: Internet
Author: User
SELECT sch.name + '. ' + t.name as [Table name], i.name as[index name], I.type_desc, ISNULL (user_updates,0) A S [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 and (NOLOCK) left Outerjoin Sys.dm_db_ind Ex_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 Oute
   Rjoin 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 this have not been used --and ISNULL (user_updates,0)-isnull (user_seeks + User_scans + user_lookups), 0) >0--only shows thoseindexes which h Ave been used--and i.index_id > 1--only Non-first indexes (i.e.non-primary key)--and <>1--only those so are not defined ASA Primary Key)--and i.is_unique_constraint<>1--only those th 
At are not classed as "uniqueconstraints". Order BY [Table Name],[index Name]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.