Delete BackUp and Restore History for databases in SQL Server 2005/2008

The msdb database stores details of all backup and restore operations, in tables. If for some reason, you want to delete the backup and restore details of a particular database, use the sp_delete_database_backuphistory stored procedure.

The following query deletes all entries for the 'PictureAlbum' database in the backup-and-restore history tables

USE msdb;


EXEC sp_delete_database_backuphistory 'PictureAlbum';

In order to delete backup and restore details for all the databases older than a specified date, use the sp_delete_backuphistory stored procedure. The query shown below deletes the historical data for all databases from the current datetime.

USE msdb;


DECLARE @dt as datetime


EXEC sp_delete_backuphistory @dt;

If you want to specify an earlier date, do it this way

USE msdb;


EXEC sp_delete_backuphistory '03/10/09';

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: