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]