Friday 19 April 2013

List all Views modified in last N days in a SQL Server Database

To list all views that were changed recently in a database, for example in the last 10 days, run the following script:
USE Database_Name
SELECT name, create_date, modify_date
FROM sys.objects
WHERE type = 'V'
AND DATEDIFF(D,modify_date, GETDATE()) < 10

Following script will list all the views which were created in last 10 days in a database, no matter if they were modified after that or not:
USE Database_Name
SELECT name, create_date, modify_date
FROM sys.objects
WHERE type = 'V'
AND DATEDIFF(D, create_date, GETDATE()) < 10

For views that were never modified after creation, the modified date and create date are the same.

No comments:

Post a Comment