Skip to content

Instantly share code, notes, and snippets.

@petesql
Last active February 19, 2024 22:39
Show Gist options
  • Save petesql/306943665d4c7e6790398b5f61333ad8 to your computer and use it in GitHub Desktop.
Save petesql/306943665d4c7e6790398b5f61333ad8 to your computer and use it in GitHub Desktop.
Get SQL Server Database Last Restore Times
-- 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];
@petesql
Copy link
Author

petesql commented Oct 26, 2022

A blog post using this script:
July 23, 2022, Get Last Database Restore DateTimes in SQL Server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment