本文主要講述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