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


One day I got a requirement to find last updates of tables in the database. Means I want to get all the tables’ last update in the 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 the above link and try to explain. See the following query it may help you to find the 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 the 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')




Related Posts

What is the Use of isNaN Function in JavaScript? A Comprehensive Explanation for Effective Input Validation

In the world of JavaScript, input validation is a critical aspect of ensuring that user-provided data is processed correctly. One indispensa...