sp_purge_jobhistory
Removes the history records for a job.
Syntax
sp_purge_jobhistory [ @job_name = ] 'job_name' | [ @job_id = ] job_id
Arguments
[@job_name =] 'job_name'
Is the name of the job for which to delete the history records. job_name is sysname, with a default of NULL. Either job_id or job_name must be specified, but both cannot be specified.
[@job_id =] job_id
Is the job identification number of the job for the records to be deleted. job_id is uniqueidentifier, with a default of NULL. Either job_id or job_name must be specified, but both cannot be specified.
Return Code Values
0 (success) or 1 (failure)
Result Sets
None
Permissions
Execute permissions default to the public role. If no parameters are supplied, all history records are removed; however, only members of the sysadmin fixed server role have permission to do this.
Examples
A. Remove history for a specific job
This example removes the history for a job named Table Archives.
USE msdb
EXEC sp_purge_jobhistory @job_name = 'Table Archives'
B. Remove history for all jobs
This example executes the procedure with no parameters to remove all history records.
USE msdb
EXEC sp_purge_jobhistory