本文主要讲述Sql server 2005 维护计划无法删除问题(sql server 2005 maintnance plan can not delete),以下为全文:
一台要改IP和主机名的数据库,只把数据库instance修改了,忘记把维护计划删除了等IP和主机名改好重启后,维护计划无法删除了。 原因是这些计划是原来连接上的OLDSvr@usr-plans. 那怎么办呢!
1。先把原数据库连接干掉:
登陆MS SQL Server Management Studio(新HOST),在 视图(view[en]/表示[jp])里的,已登陆服务器(R)调出来,然后把旧host连接删掉
2。保存以下sql,在query里执行一下:
不知道其他版本的mssql可行否,我试验成功的是mssql2005,执行后请刷新下维护计划TAB, 就发现已经删除了原主机名下的维护计划。
--Delete maintanace plan after chghostname use [msdb] set nocount on begin tran declare @SubPlanName varchar(200) set @SubPlanName='Subplan_1' --Get constraint foreign key columns declare @subPlan_id varchar(100),@job_id varchar(100) ,@msx_job_id varchar(100),@Schedule_id varchar(100) select @job_id=job_id,@msx_job_id=msx_job_id, @subPlan_id=subPlan_id from sysmaintplan_SubPlans where SubPlan_name=@SubPlanName --Delete record by order if (@SubPlan_id is not null and @SubPlan_id<>'') delete from sysmaintplan_log where SubPlan_id=@SubPlan_id if (@SubPlanName<>'' and @SubPlanName is not null) delete from sysmaintplan_SubPlans where SubPlan_Name=@SubPlanName if (@Schedule_id is 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 --After Above, you can still see these god damn maintnance plan in that tab --now use code below to refresh the msdb view delete FROM msdb.dbo.sysmaintplan_plans commit tran if @@error<>0 Print 'job failure ;-(' else Print 'job down! ;-)' set nocount off |
转自:http://maqintoshi.cnblogs.com/