Created
April 9, 2016 20:08
-
-
Save danilocbraga/5a2e3f5e5160f19725d09b43fe97c28e to your computer and use it in GitHub Desktop.
last objects created or modified in all databases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT 'modify' as [Action], db_name() as db,name,modify_date,create_date | |
INTO #eachdb | |
FROM sys.objects | |
WHERE 0=1 | |
declare @str varchar(8000) | |
set @str = 'USE [?] | |
INSERT INTO #eachdb | |
SELECT ''modify'' as [Action], db_name() as db,name,modify_date,create_date | |
FROM [?].sys.objects | |
WHERE type = ''P''AND | |
DATEDIFF(D,modify_date, GETDATE()) < 7 | |
----Change 7 to any other day value. | |
UNION ALL | |
SELECT ''create''as [Action],db_name() as db ,name,modify_date,create_date | |
FROM [?].sys.objects | |
WHERE --type = ''P''AND | |
DATEDIFF(D,create_date, GETDATE()) < 7 | |
----Change 7 to any other day value. | |
ORDER BY 3 DESC, 4 DESC | |
' | |
exec sp_MSforeachdb @str | |
Select * | |
from #eachdb | |
where db <> 'tempdb' | |
order by 3,4,5 | |
drop table #eachdb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment