23 October,2012 by Tom Collins
For many reasons SQL Server DBAs need to find the last date and time of an update on a sql table. The SQL Server DMV sys.dm_db_index_usage_stats can supply enough information to allow the DBA to make a good estimate of the time.
In this case I needed to create a list candidates for tables to be deleted. The data became bloated with a number of different temp tables .
The one drawback of using the DMV is that data is refreshed after every SQL Server restart.
This script lists all tables in the current database, with various columns assisting in deciding the last update.
SELECT tbl.name ,ius.last_user_update ,ius.user_updates ,ius.last_user_seek ,ius.last_user_scan ,ius.last_user_lookup ,ius.user_seeks ,ius.user_scans ,ius.user_lookups FROM sys.dm_db_index_usage_stats ius INNER JOIN sys.tables tbl ON (tbl.OBJECT_ID = ius.OBJECT_ID) WHERE ius.database_id = DB_ID()
last_user_update - Time of last user update.
user_updates - Number of updates by user queries.
last_user_seek - Time of last user seek .
last_user_scan - Time of last user scan.
last_user_lookup - Time of last user lookup.
user_seeks - Number of seeks by user queries.
user_scans - Number of scans by user queries.
user_lookups - Number of bookmark lookups by user queries
If you need to follow up on queries using table scans , read Find Table Scans in Query Plan Cache
SQL Server – Last DML operation
SQL Server - Calculate table size with existing data
How to request SQL Server troubleshooting
SQL Server – default trace FAQ
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |