Retrieve information about Database Restore for all Databases in SQL Server 2005/2008

If you want to find out details like when were all the databases last restored along with some more information like who restored it, recovery model etc., use the msdb..restorehistory and msdb..backupset tables as shown below:

SELECT rh.destination_database_name, rh.user_name, bk.first_lsn,

rh.restore_date, bk.backup_start_date, bk.recovery_model

FROM msdb..restorehistory rh

INNER JOIN msdb..backupset bk ON rh.backup_set_id = bk.backup_set_id

WHERE rh.destination_database_name IN

(SELECT name from sys.sysdatabases)

AND bk.type = 'D'


destination_database_name    user_name    first_lsn    restore_date    backup_start_date    recovery_model

Northwind    Suprotim-PC\Suprotim    41000000016800052    2009-03-14 17:58:36.653    2009-03-14 17:58:18.000    SIMPLE

The msdb..backupset is a very useful table and you can also get important details like the LSN (Log Sequence Number) used for a differential backup set.

About The Author

Suprotim Agarwal, MCSD, MCAD, MCDBA, MCSE, is the founder of DotNetCurry, DNC Magazine for Developers, SQLServerCurry and DevCurry. He has also authored a couple of books 51 Recipes using jQuery with ASP.NET Controls and a new one recently at The Absolutely Awesome jQuery CookBook.

Suprotim has received the prestigous Microsoft MVP award for nine times in a row now. In a professional capacity, he is the CEO of A2Z Knowledge Visuals Pvt Ltd, a digital group that represents premium web sites and digital publications comprising of Professional web, windows, mobile and cloud developers, technical managers, and architects.

Get in touch with him on Twitter @suprotimagarwal, LinkedIn or befriend him on Facebook

No comments: