Archive for the ‘SQL’ Category

Sql Server 2005 Delete Maintenance Plan Error

Monday, November 3rd, 2008

From time to time I run into this problem on a server and look around for the script.  I’m dropping this on my blog so I don’t have to hunt around or think about it again…

USE [msdb]
declare @job_name varchar(100)
set @job_name = N’insert job name here’

delete sysmaintplan_log
FROM sysmaintplan_subplans AS subplans INNER JOIN
sysjobs_view AS syjobs ON subplans.job_id = syjobs.job_id INNER JOIN
sysmaintplan_log ON subplans.subplan_id = sysmaintplan_log.subplan_id
WHERE (syjobs.name = @job_name)

 
delete sysmaintplan_subplans
FROM sysmaintplan_subplans AS subplans INNER JOIN
sysjobs_view AS syjobs ON subplans.job_id = syjobs.job_id
WHERE (syjobs.name = @job_name)