Sometimes it helps to see what database objects have been added/updated recently. If you pick up support of a new database it helps to see where the latest action has been going on. Or if you are doing development and want to make sure you have all the objects that need to get moved to the next environment.
Here is code that will return what objects have been created and when they were created *.
Just set the @dateAddedToGoBack variable to how many days back you need.
DECLARE @dateAddedToGoBack int = 30
SELECT name, modify_date
FROM sys.objects
WHERE type IN ('P', 'V', 'U', 'PK', 'TR') --SQL_STORED_PROCEDURE, VIEW, USER_TABLE, PRIMARY_KEY_CONSTRAINT, SQL_TRIGGER
AND DATEDIFF(D,create_date, GETDATE()) < @dateAddedToGoBack
Here is code that will return what objects have been updated and when they were updated *.
Just set the @dateUpdatedToGoBack variable to how many days back you need.
DECLARE @daysUpdatedToGoBack int = 30
SELECT name, modify_date
FROM sys.objects
WHERE type IN ('P', 'V', 'U', 'PK', 'TR') --SQL_STORED_PROCEDURE, VIEW, USER_TABLE, PRIMARY_KEY_CONSTRAINT, SQL_TRIGGER
AND DATEDIFF(D,modify_date, GETDATE()) < @daysUpdatedToGoBack
* Caveat: If you are doing something like a sp_refreshview or sp_recompile it could skew your results (ie. the modify dates will be the last time run).
Like this:
Like Loading...