Thursday 12 June 2014

SQL - T-SQL for last Full and Log Backup

I wanted a script to be able to list when the last backup occured on the SQL Databases that we had to check first thing as part of morning checks.

I found a number of scripts but this one met my needs:

SELECT a.name AS [Database Name],a.recovery_model_Desc AS [Recovery Model],
(select MAX(b.backup_finish_date) from msdb..backupset b where b.type = 'D' and a.name=b.database_name) AS [Full Backup],
(select MAX(b.backup_finish_date) from msdb..backupset b where b.type = 'L' and a.name=b.database_name) AS [Log Backup]
FROM master.sys.databases a


As you can see from the screen shot below of a brand spanking new SQL Express install the output also gives the Recovery Model and well as Full and Log backups.

No comments:

Post a Comment