HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

When was data last inserted/updated/deleted in a table?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
lastinserteddeletedupdatedwhenwasdatatable

Problem

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?

Solution

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.

Context

StackExchange Database Administrators Q#14496, answer score: 6

Revisions (0)

No revisions yet.