7

I have found this solution, but this information is lost everytime the SQL Server service is restarted, or in other words, it is not persistent.

Is there another way I can find out when a table was last updated even if the server has been shut down after the fact?

0

4 Answers 4

6

If the data in the other solution is acceptable to you, then you could simply roll your own data collection to make it persist. For example, create a table to store object_id and last seek/scan/update. Every n minutes, take a snapshot of the DMV. Then check the max in the snapshot, and if it's greater than the max in the rollup, update the rollup. You can keep the snapshots as history or you can clean them up over time once you've coalesced.

3

If you have access to SQL Server Enterprise edition, check out Change Tracking. That's a pretty complex solution, however. Ultimately it may just be easier to add an LastUpdated column, as already suggested.

3

I would also point out that you are going to get better milage by either creating a log table (which keeps track of inserts/deletions/updates) or adding flags with dates to your records (which would cost some additional disk space per record).

Either way SQL Server does not keep track of this by default as it would get expensive for high transaction DB's

-1

This may be helpful to you:

SELECT OBJECT_NAME(OBJECT_ID) AS DatabaseName, 
    last_user_update, *
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID( 'Database Name');
2
  • 2
    Have you read the comments to the question and the answers? At least you should address the points brought up there (e. g. SQL Server doesn't keep this info by default because it can get so expensive.) Commented Sep 9, 2013 at 8:12
  • 2
    Also in the very question you're answering: this information is lost everytime the SQL Server service is restarted - how does this answer address that problem? Commented Sep 11, 2013 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.