para mostrar las últimas copias de seguridad completas, Diff, Log para cada base de datos, considerando mostrar nulo si nunca se realiza ninguna copia de seguridad . usando pivote (modificado de la fuente )
tenga en cuenta que sin unirse a master.sys.databases y confiar solo en msdb.dbo.backupset no encontrará los dbs que no tienen copias de seguridad
SELECT name ,
recovery_model_desc ,
state_desc ,
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
AsedBasado en la solicitud de @SQLBoy, podemos escribir la consulta a continuación para incluir BackupSize y BackupSet.Name en esta consulta. Omití los datos pivotados y lo simplifiqué
WITH backupsetSummary
AS ( SELECT bs.database_name ,
bs.type bstype ,
MAX(backup_finish_date) MAXbackup_finish_date
FROM msdb.dbo.backupset bs
GROUP BY bs.database_name ,
bs.type
),
MainBigSet
AS ( SELECT db.name ,
db.state_desc ,
db.recovery_model_desc ,
bs.type ,
bs.name AS BackupSetName ,
bs.backup_size ,
bs.backup_finish_date
FROM master.sys.databases db
LEFT OUTER JOIN backupsetSummary bss ON bss.database_name = db.name
LEFT OUTER JOIN msdb.dbo.backupset bs ON bs.database_name = db.name
AND bss.bstype = bs.type
AND bss.MAXbackup_finish_date = bs.backup_finish_date
)
SELECT *
FROM MainBigSet