Skip to content

Instantly share code, notes, and snippets.

@Patricy
Created May 25, 2017 09:01
Show Gist options
  • Select an option

  • Save Patricy/b47664d4b34c5579ebb9e1754b894c62 to your computer and use it in GitHub Desktop.

Select an option

Save Patricy/b47664d4b34c5579ebb9e1754b894c62 to your computer and use it in GitHub Desktop.
Last access to the table TABLENAME in SQLServer
select DB_NAME(us.[database_id]) as [db], OBJECT_NAME(us.[object_id], us.[database_id]) as [object],
MAX(us.[last_user_lookup]) as [last_user_lookup], MAX(us.[last_user_scan]) as [last_user_scan], MAX(us.[last_user_seek]) as [last_user_seek]
from sys.dm_db_index_usage_stats as us
where us.[database_id] = DB_ID() AND us.[object_id] = OBJECT_ID('TABLENAME')
group by us.[database_id], us.[object_id];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment