Skip to content

Instantly share code, notes, and snippets.

@coryasilva
Created February 6, 2024 22:04
Show Gist options
  • Save coryasilva/1384cad2e2cac5976ccbda77a0d0261a to your computer and use it in GitHub Desktop.
Save coryasilva/1384cad2e2cac5976ccbda77a0d0261a to your computer and use it in GitHub Desktop.
mssql table usage
select top 100
d.name database_name
,t.name table_name
,sum(us.user_seeks) user_seeks
,sum(us.user_scans) user_scans
,sum(us.user_lookups) user_lookups
,sum(us.user_updates) user_updates
,max(us.last_user_seek) last_user_seek
,max(us.last_user_scan) last_user_scan
,max(us.last_user_lookup) last_user_lookup
,max(us.last_user_update) last_user_update
,sum(us.system_seeks) system_seeks
,sum(us.system_scans) system_scans
,sum(us.system_lookups) system_lookups
,sum(us.system_updates) system_updates
,max(us.last_system_seek) last_system_seek
,max(us.last_system_scan) last_system_scan
,max(us.last_system_lookup) last_system_lookup
,max(us.last_system_update) last_system_update
from sys.dm_db_index_usage_stats us (nolock)
inner join sys.tables t (nolock) on us.object_id = t.object_id
inner join sys.databases d (nolock) on us.database_id = d.database_id
where t.is_ms_shipped = 0 and us.database_id = db_id()
group by d.name, t.name
order by 1, 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment