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:
0 Comments