WITH RestoreInformation AS
(
SELECT
d.name "Database Name",
d.create_date ,
d.compatibility_level ,
d.collation_name ,
rh.*,
ROW_NUMBER() OVER (PARTITION BY d.Name ORDER BY rh.restore_date DESC) "RowNumber"
FROM master.sys.databases d
LEFT OUTER JOIN msdb.dbo.restorehistory rh ON rh.destination_database_name = d.Name where d.name ='Database Name'
)
SELECT *
FROM RestoreInformation
WHERE RowNumber = 1
--To fetch the DB restore History
SELECT
d.name "Database Name",
d.create_date ,
d.compatibility_level ,
d.collation_name ,
rh.*,
ROW_NUMBER() OVER (PARTITION BY d.Name ORDER BY rh.restore_date DESC) "RowNumber"
FROM master.sys.databases d
LEFT OUTER JOIN msdb.dbo.restorehistory rh ON rh.destination_database_name = d.Name
where d.name ='Database Name' order by RowNumber asc
No comments:
Post a Comment