How to delete job history - sp_purge_jobhistory

sp_purge_jobhistory
We can use this procedure to delete old history for jobs.



sp_purge_jobhistory
[ @job_name
or [ @job_id ,
@oldest_date
We can specify either job_name or job_id but not both.

We can get job_id from msdb.dbo.sysjobs table . job_id is uniqueidentifier.

If we specify @oldest_date then it deletes all his troy before this date else it will delete all job history.

Example

  • To delete all history for a specific job

    USE msdb ;
    GO

    EXEC dbo.sp_purge_jobhistory
    @job_name = N'Test job' ;
  • To delete history for a specific job upto specific date

    USE msdb ;
    GO

    EXEC dbo.sp_purge_jobhistory
    @job_name = N'Test job' ,
    @oldest_date = '2008-10-01'


  • To delete history for all jobs

    EXEC dbo.sp_purge_jobhistory
  • 2 comments:

    Post a Comment

    Amazon Contextual Product Ads

    Popular Posts