Quantcast
Channel: kristofdba – kristof dba
Viewing all articles
Browse latest Browse all 26

Get info on restored databases

$
0
0

With this query you’l get the last restore data for a database on your instance.

Handy if you cant remember what database you restored wen. Or in my case accidentaly restored the wrong database…

wITH LastRestores AS
(

SELECT
    DatabaseName = [d].[name] ,
    [d].[create_date] ,
    [d].[compatibility_level] ,
    [d].[collation_name] ,
    r.*,
    RowNum = ROW_NUMBER() OVER (PARTITION BY d.Name ORDER BY r.[restore_date] DESC)
FROM master.sys.databases d
LEFT OUTER JOIN msdb.dbo.[restorehistory] r ON r.[destination_database_name] = d.Name
)
SELECT *
FROM [LastRestores]

WHERE [RowNum] = 1

Viewing all articles
Browse latest Browse all 26

Trending Articles