SQL语句中怎么查询Index使用状况
这篇文章将为大家详细讲解有关SQL语句中怎么查询Index使用状况,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
SELECTsch.name+'.'+t.nameAS[TableName],i.nameAS[IndexName],i.type_desc,ISNULL(user_updates,0)AS[TotalWrites],ISNULL(user_seeks+user_scans+user_lookups,0)AS[TotalReads],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/1024asSpaceInMBFROMsys.indexesASiWITH(NOLOCK)LEFTOUTERJOINsys.dm_db_index_usage_statsASsWITH(NOLOCK)ONs.object_id=i.object_idANDi.index_id=s.index_idANDs.database_id=db_id()ANDobjectproperty(s.object_id,'IsUserTable')=1INNERJOINsys.tablesAStWITH(NOLOCK)ONi.object_id=t.object_idINNERJOINsys.schemasASschWITH(NOLOCK)ONt.schema_id=sch.schema_idLEFTOUTERJOINsys.dm_db_partition_statsASpWITH(NOLOCK)ONi.index_id=p.index_idandi.object_id=p.object_idWHERE(1=1)--ANDISNULL(user_updates,0)>=ISNULL((user_seeks+user_scans+user_lookups),0)--showsallindexesincludingthosethathavenotbeenused--ANDISNULL(user_updates,0)-ISNULL((user_seeks+user_scans+user_lookups),0)>0--onlyshowsthoseindexeswhichhavebeenused--ANDi.index_id>1--Onlynon-firstindexes(I.E.non-primarykey)--ANDi.is_primary_key<>1--OnlythosethatarenotdefinedasaPrimaryKey)--ANDi.is_unique_constraint<>1--Onlythosethatarenotclassedas"UniqueConstraints".ORDERBY[TableName],[indexname]
关于SQL语句中怎么查询Index使用状况就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。