August 09, 2011

SQL Server: Last BackUp Date

A database developer recently asked me a simple way to find the last backup date of a database. He was using SQL Server 2005. I had written a similar query for the MSDN wiki and here’s the same for my blog readers.

SQL Server Last Backup

During a backup operation, SQL Server 2005 updates the following tables:
  • msdb.dbo.backupfile,
  • msdb.dbo.backupmediaset ,
  • msdb.dbo.backupmediafamily and
  • msdb.dbo.backupset.
In the query shown above, we have made a join between sys.sysdatabase and msdb.dbo.backupset which gets us the database name, the last backup date and who took the backup. sys.sysdatabase is queried as it contains one row for each database in an instance of Microsoft SQL Server.


SQL Server BackUp

About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

No comments: