Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server: how to query when the last transaction log backup has been taken?

I would like to query for all databases (in SQL Server 2008 instance) date when the last transaction log backup has been taken. How to do that? I know that this information is somewhere, but I don't know where.

like image 211
juur Avatar asked Sep 25 '10 12:09

juur


People also ask

How can I tell when a SQL Server backup was last used?

It can be useful to periodically check when each database on a server was last backed up. The easiest way to do this on a single database is to right click on the database in SQL Server Management Studio (SSMS) and looking at the top of the Database Properties page (see the screenshot below).

How do I check SQL Server backup logs?

To view the data and log files in a backup setExpand Databases, and, depending on the database, either select a user database or expand System Databases and select a system database.

How do I query the transaction log in SQL Server?

Right-click SQL Server Logs, point to View, and then click either SQL Server Log or SQL Server and Windows Log. Expand SQL Server Logs, right-click any log file, and then click View SQL Server Log. You can also double-click any log file.

How can I get the last date of a transaction in SQL?

To get the date of the last transaction for a customer, you can execute the following query: SELECT MAX(TRANSDATE) FROM SQLBOOK.


2 Answers

SELECT   d.name,
         MAX(b.backup_finish_date) AS backup_finish_date
FROM     master.sys.sysdatabases d
         LEFT OUTER JOIN msdb..backupset b
         ON       b.database_name = d.name
         AND      b.type          = 'L'
GROUP BY d.name
ORDER BY backup_finish_date DESC
like image 67
Martin Smith Avatar answered Sep 17 '22 16:09

Martin Smith


I recommend using this modified script so you can see which database is in FULL or BULK_LOGGED recovery model and not having any LOG BACKUP.

SELECT   d.name,
         d.recovery_model_desc,
         MAX(b.backup_finish_date) AS backup_finish_date
FROM     master.sys.databases d
         LEFT OUTER JOIN msdb..backupset b
         ON       b.database_name = d.name
         AND      b.type          = 'L'
GROUP BY d.name, d.recovery_model_desc
ORDER BY backup_finish_date DESC
like image 42
PollusB Avatar answered Sep 19 '22 16:09

PollusB