September 16, 2011

SQL Server: Get Object Last Modified Date




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.

Consider this example

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).

sql-modify-date

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:

SQL Server Modified date

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.

sql-modify-date-change

Note: You can use sys.all_objects in place of sys.objects too.


Did you like this post?
kick it on DotNetKicks.com
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Madhivanan,an MSc computer Science graduate from Chennai-India, works as a works as a Lead Subject Matter Expert at a company that simplifies BIG data. He started his career as a developer working with Visual Basic 6.0, SQL Server 2000 and Crystal Report 8. As years went by, he started working more on writing queries in SQL Server. He now has good level of knowledge in SQLServer, Oracle, MySQL and PostgreSQL as well. He is also one of the leading posters at www.sqlteam.com and a moderator at www.sql-server-performance.com. His T-sql blog is at http://beyondrelational.com/blogs/madhivanan

 
  Feedback:

comments

2 Responses to "SQL Server: Get Object Last Modified Date"
  1. TheAmishMarket said...
    December 6, 2012 at 8:27 AM

    This works great for sql server but fails on Azure SQL. Does anyone know a way to get this information on azure sql.

  2. Anonymous said...
    November 4, 2013 at 3:28 PM

    Modify_Date gets updated even when a table is not changed - try running sp_recompile or DBCC DBReIndex on the table.

 

Copyright © 2009-2014 All Rights Reserved for SQLServerCurry.com by Suprotim Agarwal | Terms and Conditions