SQL Script to identify when tables in a database were last updated

In this post the focus is on identifying when tables in a database were last updated. Although this can be acheived by adding a column to tables in a database with default constraint getdate() that updates the column value with the new date and time, it cannot be used in situations with already exisiting tables where changing the DDL is not intended. In such cases, the following script can be used:

SELECT OBJECT_NAME(OBJECT_ID) AS TableName, max(last_user_update)
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID( 'your databasename') and last_user_update is not null
group by OBJECT_NAME(OBJECT_ID)

Hope it helps.

Advertisements
This entry was posted in SQL Server DBA Stuff and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s