How to know Last Backup Date in SQL Server

My friend asked me about one problem in SQL Server. He cannot find the last backup date in SQL Server. He asked me help him find scripts to query last backup date. I try a few days for find this scripts. Finally I found one scripts that can query this data.
Here is the script to find last backup date.

SELECT
a.Name AS DBName,
COALESCE(CONVERT(VARCHAR(12),MAX(b.backup_finish_date),101),
'Not yet taken') AS Last_BackUp_Date, COALESCE(CONVERT(VARCHAR(12),MAX(b.USER_NAME),101),'NA')
AS BackupBy
FROM
SYS.SYSDATABASES A
LEFT OUTER JOIN
msdb.dbo.backupset b
ON b.database_name =a.name
GROUP BY a.Name
ORDER BY a.Name

The result:


This result means my database never backup.  All backup action is stored in table msdb.dbo.backupset. We join with table sys.sysdatabases to get database name.

No comments:

Post a Comment