We walk in the dark places no others will enterWe stand on the bridge and no one may pass
--make a couple of test tablesif exists (select 1 from sys.tables where name = 'DataMod') drop table dbo.DataModgoif exists (select 1 from sys.tables where name = 'DataTest') drop table dbo.DataTestGOcreate table dbo.DataMod([schema] sysname, name sysname, modify_date datetime)gocreate table dbo.DataTest(TestCol1 int identity)go-- build a trigger to store off whenever the data is changed on the tableCREATE TRIGGER [trg_data_test] ON dbo.DataTest for update, insert, delete ASinsert into dbo.DataMod select 'dbo','DataTest', GetDate()GO-- show when the table was created and modifiedselect name, create_date, modify_date from sys.tables where object_id = object_id('dbo.DataTest')GO-- add three recordsinsert into dbo.DataTest DEFAULT VALUESGO 3-- add a new column to the tablealter table dbo.DataTest add TestCol2 uniqueidentifier default newid()GO-- show that the table was modifiedselect name, create_date, modify_date from sys.tables where object_id = object_id('dbo.DataTest')GO-- add three more recordsinsert into dbo.DataTest DEFAULT VALUESGO 3-- show that the data was added, and that the table that stores when the table was last modified has been addedselect * from dbo.DataTestselect * from dbo.DataModGO
select db_name(database_id) dbname,object_name(object_id,database_id) oname,MAX(CASE WHEN last_user_update < last_system_update THEN last_system_update ELSE last_user_update END) as LastUpdated from sys.dm_db_index_usage_stats group by database_id,object_idorder by db_name(database_id),object_name(object_id,database_id)