SQL语句实现查询Index使用状况
SELECT sch.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/1024asSpaceInMB FROMsys.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')=1 INNERJOINsys.tablesAStWITH(NOLOCK)ONi.object_id=t.object_id INNERJOINsys.schemasASschWITH(NOLOCK)ONt.schema_id=sch.schema_id LEFTOUTERJOINsys.dm_db_partition_statsASpWITH(NOLOCK)ONi.index_id=p.index_idandi.object_id=p.object_id WHERE(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]
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿