一尘不染

如何在 SQL Server 中查询上次还原日期?

sql

是否有一个 T-SQL 查询显示某个数据库的最后恢复日期时间?


阅读 83

收藏
2022-10-25

共1个答案

一尘不染

这将列出服务器上每个数据库的所有“最近”恢复:

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
2022-10-25