Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danilocbraga/5a2e3f5e5160f19725d09b43fe97c28e to your computer and use it in GitHub Desktop.
Save danilocbraga/5a2e3f5e5160f19725d09b43fe97c28e to your computer and use it in GitHub Desktop.
last objects created or modified in all databases
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