Jan 24, 2017

SQL Server- How to get last access/update time for tables in Database?

One day I got requirement to find last updates of tables in database. Means I want to get all the tables’ last update in database and did surfing on google and found the best way. Link: https://blog.sqlauthority.com/2009/05/09/sql-server-find-last-date-time-updated-for-any-table/

I am taking reference from above link and try to explain. See following query it may help you to find exact result.


SELECT OBJECT_NAME(OBJECT_ID) AS DatabaseName, last_user_update,*
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID( '<your_db_name>')


If you want to see the last update of particular table then use the following query.


SELECT OBJECT_NAME(OBJECT_ID) AS DatabaseName, last_user_update,*
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID( '<your_db_name>')
AND OBJECT_ID=OBJECT_ID('table_name')