Psst! Did you know DevelopmentNow is a mobile web site design agency?

Contact us for help mobilizing your site, or to sign up for our beta Mobile Web SDK!
all groups > sqlserver server > october 2006 >

sqlserver server : Cannot Delete Maintenance Plans - SQL 2005


tootsuite NO[at]SPAM gmail.com
10/5/2006 1:01:39 PM
[quoted text, click to view]
delete has a subplan that references it and you can't delete it until
you get rid of the subplan.

How I would do this:

1.) get job id #
2.) look up job id# in the system table in question
3.) find the subplan for the job id #
4.) delete subplan
4.) delete job

proceed with caution and don't delete anything unless 100% sure !

you should back up your jobs first, too in case something blows up

perhaps there is an easier way to do this through the menus in
Management Studio


[quoted text, click to view]
Randy H
10/5/2006 3:41:38 PM
A consultant created a maintenance plan that isn't in use and is not
enabled. I want to delete the plan but get the following error.

TITLE: Microsoft SQL Server Management Studio
------------------------------

Drop failed for Job 'Maintenance II'. (Microsoft.SqlServer.Smo)

For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.1399.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Drop+Job&LinkId=20476

------------------------------
ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch.
(Microsoft.SqlServer.ConnectionInfo)

------------------------------

The DELETE statement conflicted with the REFERENCE constraint
"FK_subplan_job_id". The conflict occurred in database "msdb", table
"dbo.sysmaintplan_subplans", column 'job_id'.
The statement has been terminated. (Microsoft SQL Server, Error: 547)

For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.1399&EvtSrc=MSSQLServer&EvtID=547&LinkId=20476

------------------------------
BUTTONS:

OK
------------------------------

I"m such a noob, how can i delete this plan?

tia,
Randy
Randy H
10/6/2006 12:00:00 AM
Is there an easier way through the menus?

I am not having any luck finding the sub plan for the job id #



[quoted text, click to view]
Mehul Patel
7/12/2010 5:23:21 AM
Below is the manual SQL fix to address this error:

Drop failed for Job ‘XXXXXXXXXXXXX’. (Microsoft.SqlServer.Smo)
The DELETE statement conflicted with the REFERENCE constraint “FK_subplan_job_id”. The conflict occurred in database “msdb”, table “dbo.sysmaintplan_subplans”, column ‘job_id’.
The statement has been terminated. (Microsoft SQL Server, Error: 547)

Here is the SQL SCRIPT to fix this:

NOTE: Replace “MaintenancePlan” with the value in the Jobs under SQL Server Agent, put the job name

=========
USE [msdb]
declare @job_name varchar(100)
set @job_name = 'CRS Daily Maintenance.Subplan_1'

-- First, delete the logs for the plan

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 the Subplan

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)

-- Delete the actual job (You can do the same thing through Management Studio (Enterprise Manager)

delete
from msdb.dbo.sysjobs_view where name = @job_name

==========
Above Script will fetch Job ID for maintenance plan and Sub Maintenance Plan from the system.
==========

If you get this error:

The DELETE statement conflicted with the REFERENCE constraint "FK__sysjobsch__job_i__276EDEB3".
The conflict occurred in database "msdb", table "dbo.sysjobschedules", column 'job_id'.

Open the Maintenance Sub Job Plan Under SQL JObs Agent and Delete the Schedules and Run the Above Query Again – It will Delete the Maintenance & Sub Maintenance Job
- You can create new Maintenance Plan As you require.

From http://www.developmentnow.com/g/118_2006_10_0_0_831628/Cannot-Delete-Maintenance-Plans--SQL-2005.htm

Posted via DevelopmentNow.com Groups
AddThis Social Bookmark Button