Created
August 27, 2024 09:07
-
-
Save thebirk/637b6d17fbeac30eec49a27c37608a53 to your computer and use it in GitHub Desktop.
Check index usage SQL Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* https://stackoverflow.com/a/5146398/1088079 */ | |
SELECT | |
row_number() over(order by user_seeks,user_lookups,user_scans), | |
[Database] = d.name, | |
[Schema]= s.name, | |
[Table]= o.name, | |
[Index]= x.name, | |
[Scans] = user_scans, | |
[Seeks] = user_seeks, | |
[Lookups] = user_lookups, | |
[Last Scan] = last_user_scan, | |
[System Scans] = system_scans | |
FROM sys.dm_db_index_usage_stats u | |
INNER JOIN sys.sysdatabases d on u.database_id = d.dbid | |
INNER JOIN sys.sysindexes x on u.object_id = x.id and u.index_id = x.indid | |
INNER JOIN sys.objects o on u.object_id = o.object_id | |
INNER JOIN sys.schemas s on s.schema_id = o.schema_id | |
where x.name is not null | |
order by 1 desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment