共用方式為


sp_update_alert (Transact-SQL)

更新現有警示的設定。

主題連結圖示 Transact-SQL 語法慣例

語法

sp_update_alert 
     [ @name =] 'name' 
     [ , [ @new_name =] 'new_name'] 
     [ , [ @enabled =] enabled] 
     [ , [ @message_id =] message_id] 
     [ , [ @severity =] severity] 
     [ , [ @delay_between_responses =] delay_between_responses] 
     [ , [ @notification_message =] 'notification_message'] 
     [ , [ @include_event_description_in =] include_event_description_in] 
     [ , [ @database_name =] 'database'] 
     [ , [ @event_description_keyword =] 'event_description_keyword'] 
     [ , [ @job_id =] job_id | [@job_name =] 'job_name'] 
     [ , [ @occurrence_count = ] occurrence_count] 
     [ , [ @count_reset_date =] count_reset_date] 
     [ , [ @count_reset_time =] count_reset_time] 
     [ , [ @last_occurrence_date =] last_occurrence_date] 
     [ , [ @last_occurrence_time =] last_occurrence_time] 
     [ , [ @last_response_date =] last_response_date] 
     [ , [ @last_response_time =] last_response _time]
     [ , [ @raise_snmp_trap =] raise_snmp_trap]
     [ , [ @performance_condition =] 'performance_condition' ] 
     [ , [ @category_name =] 'category']
     [ , [ @wmi_namespace = ] 'wmi_namespace' ]
     [ , [ @wmi_query = ] 'wmi_query' ]

引數

  • [ @name =] 'name'
    要更新的警示名稱。 name 是 sysname,沒有預設值。

  • [ @new_name =] 'new_name'
    警示的新名稱。 名稱必須是唯一的。 new_name 是 sysname,預設值是 NULL。

  • [ @enabled =] enabled
    指定要啟用 (1) 或不啟用 (0) 警示。 enabled 是 tinyint,預設值是 NULL。 您必須啟用警示,才能引發警示。

  • [ @message_id =] message_id
    警示定義的新訊息或錯誤號碼。 message_id 通常對應於 sysmessages 資料表中的錯誤號碼。 message_id 是 int,預設值是 NULL。 只有在警示的嚴重性層級設定值是 0 時,才能使用訊息識別碼。

  • [ @severity =] severity
    警示定義的新嚴重性層級 (125)。 任何傳給 Windows 應用程式記錄檔且含有指定嚴重性的 Microsoft SQL Server 訊息都會啟動警示。 severity 是 int,預設值是 NULL。 只有在警示的訊息識別碼設定值是 0 時,才能使用嚴重性層級。

  • [ @delay_between_responses =] delay_between_responses
    每次回應警示之間的新等待時間 (以秒為單位)。 delay_between_responses 是 int,預設值是 NULL。

  • [ @notification_message =] 'notification_message'
    附加在電子郵件、net send 或呼叫器通知中,傳給操作員之附加訊息的修訂文字。 notification_message 是 nvarchar(512),預設值是 NULL。

  • [ @include_event_description_in =] include_event_description_in
    指定是否應該將 Windows 應用程式記錄檔的 SQL Server 錯誤描述併入通知訊息中。 include_event_description_in 是 tinyint,預設值為 NULL,可以是下列一個或多個值。

    說明

    0

    1

    電子郵件

    2

    呼叫器

    4

    net send

    7

    全部

  • [ @database_name =] 'database'
    必須發生錯誤才會引發警示的資料庫名稱。 database 是 sysname.。不允許以括號 ([ ]) 括住名稱。 預設值是 NULL。

  • [ @event_description_keyword =] 'event_description_keyword'
    必須在錯誤訊息記錄的錯誤描述中找到的字元序列。 您可以使用 Transact-SQL LIKE 運算式模式比對字元。 event_description_keyword 是 nvarchar(100),預設值是 NULL。 在篩選物件名稱時,這個參數很有用 (如 %customer_table%)。

  • [ @job_id =] job_id
    作業識別碼。 job_id 是 uniqueidentifier,預設值是 NULL。 如果指定 job_id,就必須省略 job_name。

  • [ @job_name =] 'job_name'
    為回應這個警示而執行之作業的名稱。 job_name 是 sysname,預設值是 NULL。 如果指定 job_name,就必須省略 job_id。

  • [ @occurrence_count = ] occurrence_count
    重設警示的發生次數。 occurrence_count 是 int,預設值是 NULL,而且只能設為 0

  • [ @count_reset_date =] count_reset_date
    重設前次重設出現計數的日期。 count_reset_date 是 int,預設值是 NULL。

  • [ @count_reset_time =] count_reset_time
    重設前次重設出現計數的時間。 count_reset_time 是 int,預設值是 NULL。

  • [ @last_occurrence_date =] last_occurrence_date
    重設上次發生警示的日期。 last_occurrence_date 是 int,預設值是 NULL,而且只能設為 0

  • [ @last_occurrence_time =] last_occurrence_time
    重設上次發生警示的時間。 last_occurrence_time 是 int,預設值是 NULL,而且只能設為 0

  • [ @last_response_date =] last_response_date
    重設 SQLServerAgent 服務上次回應警示的日期。 last_response_date 是 int,預設值是 NULL,而且只能設為 0

  • [ @last_response_time =] last_response_time
    重設 SQLServerAgent 服務上次回應警示的時間。 last_response_time 是 int,預設值是 NULL,而且只能設為 0

  • [ @raise_snmp_trap =] raise_snmp_trap
    已保留。

  • [ @performance_condition =] 'performance_condition'
    這是用 'itemcomparatorvalue' 格式來表示的值。 performance_condition 是 nvarchar(512),預設值為 NULL,由這些元素組成。

    格式元素

    說明

    Item

    計數器的效能物件、效能計數器或具名執行個體

    Comparator

    它是下列運算子之一:><=

    Value

    計數器的數值

  • [ @category_name =] 'category'
    警示類別目錄的名稱。 category 是 sysname,預設值是 NULL。

  • [ @wmi_namespace= ] 'wmi_namespace'
    要查詢事件的 WMI 命名空間。 wmi_namespace 是 sysname,預設值是 NULL。

  • [ @wmi_query= ] 'wmi_query'
    指定警示之 WMI 事件的查詢。 wmi_query 是 nvarchar(512),預設值是 NULL。

傳回碼值

0 (成功) 或 1 (失敗)

備註

只有寫入 Microsoft Windows 應用程式記錄檔的 sysmessages 能夠引發警示。

sp_update_alert 只會變更提供了參數值的警示設定。 如果省略某個參數,就會保留目前的設定。

權限

若要執行這個預存程序,使用者必須是系統管理員 (sysadmin) 固定伺服器角色的成員。

範例

下列範例會將 Test Alert 已啟用的設定值改成 0。

USE msdb ;
GO

EXEC dbo.sp_update_alert
    @name = N'Test Alert',
    @enabled = 0 ;
GO

請參閱

參考

sp_add_alert (Transact-SQL)

sp_help_alert (Transact-SQL)

系統預存程序 (Transact-SQL)