Suppose you want to track when was the last time a particular SQL Server object (table, view, procedure etc) was modified. To do so, you can make use of the system views - sys.objects and sys.all_objects.
create table test(id int, names varchar(100))
GO
select name, create_date, modify_date
from sys.objects
where name='test'
The above gives you the create_date and modify_date (in this case both will be the same).
Now alter the table to change the width of the column names
alter table test
alter column names varchar(150)
GO
Now execute the same select statement again:
Executing the above statement gives you the create_date and modify_date (in this case modify_date will be greater than the create_date). Whenever there is a column change in the table, the modify_date column gets updated.
Note: You can use sys.all_objects in place of sys.objects too.
3 comments:
This works great for sql server but fails on Azure SQL. Does anyone know a way to get this information on azure sql.
Modify_Date gets updated even when a table is not changed - try running sp_recompile or DBCC DBReIndex on the table.
This seems to be showing me the last time that the contents of the field were updated unless it is also showing the last time a back up was done. The table has not been altered in months yet modify_date is showing two days ago.
Post a Comment