SQL Server: Get Data Update Time – Quick Guide
In SQL Server, you can retrieve the update time of data using either of the following two methods:
- the dynamic management view dm_db_index_usage_stats
SELECT last_user_update
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID('YourDatabaseName')
AND OBJECT_ID = OBJECT_ID('YourTableName')
This query will return the time of the last update to the table data.
- tables in the system
- View containing information about index usage in the database.
SELECT
name AS TableName,
last_user_update AS LastUpdate
FROM sys.tables t
JOIN sys.dm_db_index_usage_stats u
ON t.object_id = u.object_id
WHERE database_id = DB_ID('YourDatabaseName')
AND t.name = 'YourTableName'
This query will return the time of the last update for the specified table.
Please note that in the above query, replace YourDatabaseName and YourTableName with the name of the database and table you want to query, respectively.