程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> Sql server 2005 維護計劃無法刪除?

Sql server 2005 維護計劃無法刪除?

編輯:關於MYSQL數據庫

       本文主要講述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
    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved