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

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.