Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
TSQL 15
BRH 13
SQL Server 13
#SQL Server 12
#TSQL 8
#SQLServer 4
SQL Server Agent 3
Stored Procedure 2
SQL server Jobs 2
Change Data Capture CDC 2

Archive · View All
November 2010 4
October 2010 3
April 2011 3
March 2011 3
January 2012 2
November 2011 2
August 2011 2
September 2010 1
October 2011 1

Stored Procedure to Purge MSDB Job History

Jan 27 2012 10:50AM by Manjunath C Bhat   

Purging your MSDB Job History is sometime very important which helps you read the Jos history in GUI very easily and keeps which only required number of days. You can add this in your Maintenance Plan or using a SSIS Package. I found one of the way a Stored Procedure to do the same. This Procedure accepts a Parameter @DaysToPurge. This is the number of days back for which you want to keep the History. I have used the existing MS SP’s for this tasks.

 

--Drop stored procedure if it already exists
USE [YourDatabaseName]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_PurgeMSDBHistory]')
AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_PurgeMSDBHistory]
GO
--Create Procedure
--Parameter @DaysToPurge int -- This is the number of days back data to be kept
CREATE PROCEDURE usp_PurgeMSDBHistory
@DaysToPurge as int
AS
BEGIN
DECLARE @VarDate DATETIME
DECLARE @DTP as INT
SET @DTP = @DaysToPurge
SELECT @VarDate = CAST((GETDATE() - @DTP) AS DATETIME)
EXEC MSDB.DBO.sp_delete_backuphistory @VarDate
EXEC MSDB.DBO.sp_purge_jobhistory  @oldest_date=@VarDate
EXECUTE MSDB..sp_maintplan_delete_log NULL,NULL,@VarDate
END
GO

Thanks and Regards,

Manjunath C Bhat.

Suggestions and comments are always welcome.

Tags: TSQL, #TSQL, Stored Procedure,


Manjunath C Bhat
102 · 2% · 511
1
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

4  Comments  

  • Hi This can be easily done from the the History page of SQL agent properties. Yes internal it use these procedure.

    Thanks Nelson www.PracticalSqlDba.com

    commented on Apr 3 2012 9:12PM
    Nelson John A
    478 · 0% · 78
  • Hi, Yes it can be done from the History Page, but what is you want to be scheduled and history should be clean on periodic bases, during those conditions this comes handy as we can schedule it as Job. If its a One time or on Need bases then your option is sufficient.

    Thank you, Manjunath C Bhat

    commented on Apr 4 2012 4:01AM
    Manjunath C Bhat
    102 · 2% · 511
  • Hi Once you set this on history page , rest it will take care . It will automatlcally delete the history . You do not have to maintain a seperate job or maintenance plan

    Thanks Nelson www.PracticalSqlDba.com

    commented on Apr 4 2012 4:13AM
    Nelson John A
    478 · 0% · 78
  • Hi. Got it. Had not checked previously. Thank you

    commented on Apr 5 2012 2:34AM
    Manjunath C Bhat
    102 · 2% · 511

Your Comment


Sign Up or Login to post a comment.

"Stored Procedure to Purge MSDB Job History" rated 5 out of 5 by 1 readers
Stored Procedure to Purge MSDB Job History , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]