Skip to content

Instantly share code, notes, and snippets.

@bartread
Created January 4, 2017 07:47
Show Gist options
  • Save bartread/4b9438fce3dd6fcb4f6c4e0f2b2fd2a7 to your computer and use it in GitHub Desktop.
Save bartread/4b9438fce3dd6fcb4f6c4e0f2b2fd2a7 to your computer and use it in GitHub Desktop.
Get most used tables in SQL Server
--get most used tables
SELECT
db_name(ius.database_id) AS DatabaseName,
t.NAME AS TableName,
SUM(ius.user_seeks + ius.user_scans + ius.user_lookups) AS NbrTimesAccessed
FROM sys.dm_db_index_usage_stats ius
INNER JOIN sys.tables t ON t.OBJECT_ID = ius.object_id
WHERE database_id = DB_ID('YOUR_DATABASE_HERE')
GROUP BY database_id, t.name
ORDER BY SUM(ius.user_seeks + ius.user_scans + ius.user_lookups) DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment