SQL Server 2005 Maintenance plan cannot be deleted?

Source: Internet
Author: User
Tags management studio sql server management sql server management studio

This article focuses on SQL Server 2005 maintenance plans that cannot be removed (SQL Server maintnance plan can not delete), and the following is full text:

A database to change the IP and host name, only the database instance modified, forget to maintain the plan to remove the IP and host name after the restart, maintenance plan can not be deleted. The reason is that these plans are oldsvr@usr-plans on the original connection. How about that!

1. First connect the original database to kill:

Login to MS SQL Server Management Studio (new host), in the view (View[en]/said [JP]), the login server (R), and then delete the old host connection

2. Save the following SQL and execute it in query:

Do not know the other version of MSSQL feasible No, I successfully tested the mssql2005, after the implementation, please refresh the Maintenance Plan tab, found that the original host has been deleted under the name of the maintenance plan.

--delete maintanace plan after chghostname 
Use [ MSDB]&NBSP
SET NOCOUNT ON&NBSP
begin tran 
declare @SubPlanName varchar ()  
SET @ Subplanname= ' subplan_1 '  

--get constraint foreign key columns 
declare @subPlan_id varchar (100), @job_id varchar (m)  
, @msx_job_id varchar (m), @Schedule_id varchar  
Select @job_id =job_id,@ MSX_JOB_ID=MSX_JOB_ID,&NBSP
@subPlan_id =subplan_id from Sysmaintplan_subplans where Subplan_name= @SubPlanName &NBSP

--delete record by order 
if (@SubPlan_id isn't null and @SubPlan_id <> ')  
Delete From Sysmaintplan_log where subplan_id= @SubPlan_id  

if (@SubPlanName <> "and @SubPlanName is not NULL &NBSP
Delete from Sysmaintplan_subplans where subplan_name= @SubPlanName  

if (@Schedule_id was not null and @Schedule_id <> ')  
Delete from SYsschedules where schedule_id= @Schedule_id  

if (@job_id is not null and @job_id <> ")  
Delete From Sysjobs where job_id= @job_id the  

--after Above, you can still, and so on God damn maintnance TAB&NBSP
--now Use code below to refresh the msdb view 

delete 
from Msdb.dbo.sysmaintplan_pla NS&NBSP
Commit tran 
if @ @error <>0 Print ' job failure;-('  
Else Print ' job down!;-) '  < br>
SET NOCOUNT off
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.