Listing When Full, Differential and Log Backups of All Databases Are Taken in SQL Server
Hello everyone,
In this article, I will try to give information about listing when Full, Differential and Log backups of all databases are taken in SQL Server.
In SQL Server, in some cases, you may want to list when Full, Differential and Log backups of all databases were taken.
You can easily do this using the code below.
SELECT
substring(s.name, 1, 50) AS 'Veritabanı_Adi'
,b.backup_start_date AS 'Full DB Backup Tarihi'
,c.backup_start_date AS 'Differential Backup Tarihi'
,d.backup_start_date AS 'Transaction Log Tarihi'
FROM master..sysdatabases s
LEFT OUTER JOIN msdb..backupset b
ON s.name = b.database_name
AND b.backup_start_date = (SELECT
MAX(backup_start_date) AS 'Full DB Backup Tarihi'
FROM msdb..backupset
WHERE database_name = b.database_name
AND TYPE = 'D') -- full database backups only, not log backups
LEFT OUTER JOIN msdb..backupset c
ON s.name = c.database_name
AND c.backup_start_date = (SELECT
MAX(backup_start_date) 'Differential Backup Tarihi'
FROM msdb..backupset
WHERE database_name = c.database_name
AND TYPE = 'I')
LEFT OUTER JOIN msdb..backupset d
ON s.name = d.database_name
AND d.backup_start_date = (SELECT
MAX(backup_start_date) 'Log Backup Tarihi'
FROM msdb..backupset
WHERE database_name = d.database_name
AND TYPE = 'L')
WHERE s.name <> 'tempdb'
ORDER BY s.name
When you run the above code, you will see a result similar to the one below.
As you can see, we have listed when Full, Differential and Log backups of all databases are taken.
Good luck to everyone in business and life.