Last active
February 19, 2024 22:39
-
-
Save petesql/306943665d4c7e6790398b5f61333ad8 to your computer and use it in GitHub Desktop.
Get SQL Server Database Last Restore Times
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
-- get database last restore time | |
SELECT | |
[rs].[destination_database_name] AS [DatabaseName], | |
[rs].[restore_date] AS [LastRestoreDate] | |
FROM | |
msdb..restorehistory rs | |
INNER JOIN | |
(SELECT | |
[destination_database_name], | |
MAX([restore_date]) AS [last_restore_date] | |
FROM | |
msdb..restorehistory | |
GROUP BY | |
[destination_database_name]) AS [max_rs] | |
ON | |
[rs].[destination_database_name] = [max_rs].[destination_database_name] | |
AND [rs].[restore_date] = [max_rs].[last_restore_date] | |
ORDER BY | |
[rs].[destination_database_name]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A blog post using this script:
July 23, 2022, Get Last Database Restore DateTimes in SQL Server