How to Find The Last Time the Database was Backed Up in SQL Server
Hello to everyone,
In this article, I will provide information about the last time the database was backed up in SQL Server.
In SQL Server, in some cases, you may want to know when the database was last backed up.
You can easily do this using the code below.,
SELECT db.name AS 'Database', db.database_id, CASE WHEN (b.type) = 'D' THEN 'Full' WHEN (b.type) = 'I' THEN 'Differential' WHEN (b.type) = 'L' THEN 'Log' ELSE 'Other' END AS 'Type', b.backup_start_date, b.backup_finish_date, b.user_name FROM sys.databases db LEFT OUTER JOIN msdb.dbo.backupset b ON db.name = b.database_name AND b.type = 'D' --WHERE db.database_id NOT IN (2) GROUP BY db.name, db.database_id, b.user_name, b.backup_start_date, b.backup_finish_date, b.type ORDER BY backup_finish_date DESC;
When you run the above code, you will see a result similar to the one below.
As you can see, the last backup dates of the database are seen.
Good luck to everyone in business and life.