在网上找到了这个漂亮的查询(不记得要感谢谁了),并尝试修改它,以便没有值的 backup_finish_date 不会输出为 NULL,但一直没能弄明白。这个查询完全符合我的要求(我自己也学会了),唯一的例外是输出 NULL。我还想把它格式化为 dd-mm-yyyy hh:mm
SELECT name ,
recovery_model_desc as 'Recovery Model' ,
state_desc as 'State',
d AS 'Last Full Backup' ,
i AS 'Last Differential Backup' ,
l AS 'Last log Backup'
FROM ( SELECT db.name ,
db.state_desc ,
db.recovery_model_desc ,
type ,
backup_finish_date
FROM master.sys.databases db
LEFT OUTER JOIN msdb.dbo.backupset a ON a.database_name = db.name
) AS Sourcetable
PIVOT
( MAX(backup_finish_date) FOR type IN ( D, I, L ) ) AS MostRecentBackup
WHERE (name NOT IN ('master','msdb','model','tempdb'))