Monday, December 1, 2014

Query to get Last restored database in SQL Server

You can use below query to get the list of all database restored in SQL Server:

SELECT [RS].[Destination_Database_Name] AS [Destination DB Name],
[RS].[Restore_Date] AS [Restore Date],
[BS].[Backup_Start_Date] AS [Backup Start Date],
[BS].[Backup_Finish_Date] AS [Backup End Date],
[BS].[Database_Name] as [Source Database Name],
[BMF].[Physical_Device_Name] AS [Backup File Used For Restore]
FROM msdb..RestoreHistory RS
INNER JOIN msdb..BackupSet BS
ON [RS].[Backup_Set_ID] = [BS].[Backup_Set_ID]
INNER JOIN msdb..BackupMediaFamily BMF
ON [BS].[Media_Set_ID] = [BMF].[Media_Set_ID]
ORDER BY [RS].[Restore_Date] DESC

No comments:

Post a Comment