Quantcast
Channel: SQL Backup Archives - SQL Authority with Pinal Dave
Viewing all articles
Browse latest Browse all 110

SQL SERVER – Get Last Restore Date

$
0
0

Let us learn how to get the last restore date for the backup in SQL Server. Here is a very simple script for the same.

SELECT
[d].[name] AS [Database],
[d].[create_date],
[d].[compatibility_level],
rh.restore_date,
rh.restore_history_id,
rh.restore_type
FROM master.sys.databases d
LEFT OUTER JOIN msdb.dbo.[restorehistory] rh
ON rh.[destination_database_name] = d.Name
ORDER BY [Database], restore_history_id

Well, that’s it. It will give you all the necessary history from the msdb database.

SQL SERVER - Get Last Restore Date RestoreDate-800x219

If you want to clear any backup or restore history for the database, you can just run the following simple script and it will remove your history from the msdb database.

Here is an example of how you can remove the history for the AdventureWorks Database.

USE msdb;
GO
EXEC sp_delete_database_backuphistory @database_name = 'AdventureWorks'; 

Well, that’s it for today. Let me know your thoughts about this blog post.

Here are my few recent videos and I would like to know what is your feedback about them. Do not forget to subscribe SQL in Sixty Seconds series.

Reference: Pinal Dave (http://blog.SQLAuthority.com)

First appeared on SQL SERVER – Get Last Restore Date


Viewing all articles
Browse latest Browse all 110

Trending Articles