Get the most recent post date from each database

0

Please login or register to vote for this query.

(click on this box to dismiss)

Loop through all of the databases on the server with sp_msforeachdb, and get the most recent post from each of them. Helpful to see which databases have the most up-to-date data. Doesn't matter which site you run this on at data.stackexchange.com - you'll get data for all sites.

Database Administrators

Q&A for database professionals who wish to improve their database skills and learn from others in the community

CREATE TABLE #RestoreDates (DBname NVARCHAR(255), MostRecentPost DATETIME);
EXEC sp_msforeachdb 'USE [?]; IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ''Posts'') 
INSERT INTO #RestoreDates SELECT TOP 1 ''?'' AS DBname, CreationDate FROM dbo.Posts ORDER BY Id DESC;';
SELECT * FROM #RestoreDates ORDER BY DBname;

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results