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

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.


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

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


TheAmishMarket said...

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

Anonymous said...

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

joeller said...

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.