Sql-Server

如何在 SQL Server 中查詢上次還原日期?

  • September 9, 2021

是否有一個 T-SQL 查詢顯示某個數據庫的最後恢復日期時間?

這將列出伺服器上每個數據庫的所有“最近”恢復:

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

可以使用的腳本是:

declare @DB sysname = 'MyDB';
select * from msdb.dbo.restorehistory where destination_database_name = @DB;

引用自:https://dba.stackexchange.com/questions/33703