2013-06-12 41 views
0

我繼承了一個SQL服務器(2008)的維護,我想修改一些系統存儲過程。這些是用戶定義的系統存儲過程(例如:sys.sp_customproc)。我只能假設它們是作爲系統過程創建的,因此它們可以在多個數據庫之間共享?但無論如何,我需要修改它們。SQL Server 2008中修改系統存儲過程

下面是其中一個例子。

USE [msdb] 
GO 
/****** Object: StoredProcedure [sys].[sp_dbmmonitorhelpmonitoring] Script Date: 06/12/2013 13:16:52 ******/ 
SET ANSI_NULLS ON 
GO 
SET QUOTED_IDENTIFIER ON 
GO 
ALTER procedure [sys].[sp_dbmmonitorhelpmonitoring] 
as 
begin 
set nocount on 
if (is_srvrolemember(N'sysadmin') <> 1) 
    begin 
     raiserror(21089, 16, 1) 
     return (1) 
    end 

declare @freq_type    int, -- 4 = daily 
     @freq_interval   int, -- Every 1 days 
     @freq_subday_type  int, -- 4 = based on Minutes 
     @freq_subday_interval int, -- interval 
     @job_id     uniqueidentifier, 
     @schedule_id   int, 
     @retention_period  int, 
     @jobname    nvarchar(256) 

select @jobname = isnull(formatmessage(32047), N'Database Mirroring Monitor Job') 

select @job_id = job_id from msdb.dbo.sysjobs where name = @jobname 
if (@job_id is null) -- if the job does not exist, error out 
begin 
    raiserror(32049, 16, 1) 
    return 1 
end 

select @schedule_id = schedule_id from msdb.dbo.sysjobschedules where job_id = @job_id 
select @freq_type = freq_type, 
     @freq_interval = freq_interval, 
     @freq_subday_type = freq_subday_type, 
     @freq_subday_interval = freq_subday_interval 
    from msdb.dbo.sysschedules where schedule_id = @schedule_id 

-- If the frequency parameters are not what we expect then return an error 
-- Someone has changed the job schedule on us 
if (@freq_type <> 4) or (@freq_interval <> 1) or (@freq_subday_type <> 4) 
begin 
    raiserror(32037, 16, 1) 
    return 1 
end 

select @freq_subday_interval update_period 

return 0 
end 

當我試着執行它時,我得到的錯誤:

消息208,級別16,狀態6,過程sp_dbmmonitorhelpmonitoring,行46 無效的對象名稱sys.sp_dbmmonitorhelpmonitoring「。

我的登錄名是「山」,我映射到[MSDB]數據庫用戶「DBO」。我如何修改這個存儲過程?

+0

那麼它很簡單:有,你執行這個名爲'sys.sp_dbmmonitorhelpmonitoring'在數據庫中沒有你的存儲過程。 – phadaphunk

回答

0

一旦你將其標記爲「系統存儲過程」你不能改變一個SP。相反,您必須刪除它,重新創建它並再次將其標記爲系統存儲過程(使用sp_ms_marksystemobject)。 我相信你已經意識到如何處理被標記爲「系統」的東西是非常危險的。我覺得有責任強烈建議您在嘗試任何此類之前進行大量備份。即備份:主,模型和MSDB。

相關問題