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.

Listing When Full Differential and Log Backups of All Databases Are Taken in SQL Server

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.

106 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!