Sql server get restore datetime | restore history sql server

List Out All Database Restore Date Time.
  WITH LastRestores AS
(
SELECT
    DatabaseName = db.name ,
    db.create_date ,
    db.compatibility_level ,
    db.collation_name ,
    r.*,
    RowNum = ROW_NUMBER() OVER (PARTITION BY db.Name ORDER BY r.[restore_date] DESC)
FROM master.sys.databases db
LEFT OUTER JOIN msdb.dbo.restorehistory r ON r.destination_database_name= db.Name
)
SELECT *
FROM [LastRestores]
WHERE [RowNum] = 1 order by DatabaseName
Result:

Post a Comment

0 Comments