Getting Started with Adobe After Effects - Part 6: Motion Blur
A collection of quick technology learning tips from what people around you learn every day

When was the last time your SQL Server database was restored

Jul 25 2012 12:00AM by Latheesh NK   

I have come across the method of finding last time the SQL server DB has been restored. I believe it would be helpful for most of us.

Please refer the link for the details.

DECLARE @dbname sysname, @days int
SET @dbname = NULL --substitute for whatever database name you want
SET @days = -30 --previous number of days, script will default to 30
SELECT
 rsh.destination_database_name AS [Database],
 rsh.user_name AS [Restored By],
 CASE WHEN rsh.restore_type = 'D' THEN 'Database'
  WHEN rsh.restore_type = 'F' THEN 'File'
  WHEN rsh.restore_type = 'G' THEN 'Filegroup'
  WHEN rsh.restore_type = 'I' THEN 'Differential'
  WHEN rsh.restore_type = 'L' THEN 'Log'
  WHEN rsh.restore_type = 'V' THEN 'Verifyonly'
  WHEN rsh.restore_type = 'R' THEN 'Revert'
  ELSE rsh.restore_type 
 END AS [Restore Type],
 rsh.restore_date AS [Restore Started],
 bmf.physical_device_name AS [Restored From], 
 rf.destination_phys_name AS [Restored To]
FROM msdb.dbo.restorehistory rsh
 INNER JOIN msdb.dbo.backupset bs ON rsh.backup_set_id = bs.backup_set_id
 INNER JOIN msdb.dbo.restorefile rf ON rsh.restore_history_id = rf.restore_history_id
 INNER JOIN msdb.dbo.backupmediafamily bmf ON bmf.media_set_id = bs.media_set_id
WHERE rsh.restore_date >= DATEADD(dd, ISNULL(@days, -30), GETDATE()) --want to search for previous days
AND destination_database_name = ISNULL(@dbname, destination_database_name) --if no dbname, then return all
ORDER BY rsh.restore_history_id DESC

GO
Read More..   [20 clicks]

Published under: SQL Server Tips ·  ·  ·  · 


Latheesh NK
55 · 3% · 1115
6
 
1
 
 
0
Incorrect
 
0
Interesting
 



Submit

1  Comments  

  • Hi,

    Thanks for posting, It helps a lot to find my Dev db last restored date.

    Thanks Durga

    commented on Jul 31 2012 3:36AM
    dpechetti
    1059 · 0% · 24

Your Comment


Sign Up or Login to post a comment.

"When was the last time your SQL Server database was restored" rated 5 out of 5 by 6 readers
When was the last time your SQL Server database was restored , 5.0 out of 5 based on 6 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]