DevJef's Mumbo-Jumbo

«There's a bit of SQL in all of us»


News


How many times do you wonder about when an object was last updated? You can find out by using the default sysobjects in SQL Server:

 

USE Adventureworks


DECLARE @DBID INT = DB_ID('Adventureworks')


SELECT
	o.name AS TableName,
	ddius.*
FROM sys.dm_db_index_usage_stats ddius
JOIN sys.objects o
	ON o.object_id = ddius.object_id
WHERE database_id = @DBID
ORDER BY ddius.last_user_update DESC

 

This will give you the last_user_update, which is based on indexes. The Insert, Delete or Update are stored in the sys properties of the database. So this only works if there is an index of some sort is used on the object!


Comments

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Comment:
Verification: