我正在尝试创建一份报告,详细说明我们 SQL Server 上的最新备份。截至目前,我已经写了这个:
select
[Server_Name] = a.server_name,
[Database_Name] = a.database_name,
[Last_Backup] = max(a.backup_finish_date),
[Backup_Type] = CASE A.type
WHEN 'D' THEN 'FULL'
WHEN 'I' THEN 'Differential'
WHEN 'L' THEN 'Log'
WHEN 'F' THEN 'FileGroup'
WHEN 'G' THEN 'FileGroup Differential'
WHEN 'P' THEN 'Partial'
WHEN 'Q' THEN 'Partial Differential'
END,
[Backup_Set] = b.name,
[Days_Since_Last_Backup] = DATEDIFF(d,(max(a.backup_finish_Date)),GETDATE())
from msdb.dbo.backupset AS a
INNER JOIN msdb.dbo.backupset as b ON a.backup_set_id = b.backup_set_id
GROUP BY a.database_name, a.server_name, b.name, a.type
ORDER BY database_name
我想更改它,以便列显示以下内容:
Server_Name, Database_Name, Last_Full_Backup, Last_Diff_Backup, Last_Log_Backup,
Backup_Set, Days_Since_Last_Full
为了显示 、 和 的日期,Last_Full_Backup
我想我必须做一些旋转,但我不太确定如何(我对旋转非常不熟悉)。Last_Diff_Backup
Last_Log_Backup
任何帮助将不胜感激。提前感谢大家。