sp_add_notification (Transact-SQL)

設定警示通知。

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

語法

sp_add_notification [ @alert_name = ] 'alert' , 
    [ @operator_name = ] 'operator' , 
    [ @notification_method = ] notification_method

引數

  • [@alert_name= ] 'alert'
    這項通知的警示。alert 是 sysname,沒有預設值。

  • [@operator_name= ] 'operator'
    發生警示時所要通知的操作員。operator 是 sysname,沒有預設值。

  • [@notification_method= ] notification_method
    用來通知操作員的方法。notification_method 是 tinyint,沒有預設值。notification_method 可以是利用 OR 邏輯運算子組合起來的一或多個這些值。

    描述

    1

    電子郵件

    2

    呼叫器

    4

    net send

傳回碼值

0 (成功) 或 1 (失敗)

結果集

備註

sp_add_notification 必須從 msdb 資料庫中執行。

SQL Server Management Studio 提供了一種簡單的圖形方式供您管理整個警示系統。建議您利用 Management Studio 來設定您的警示基礎結構。

若要傳送通知來回應警示,您必須先設定 SQL Server Agent 來傳送郵件。如需詳細資訊,請參閱<SQL Server Agent Mail>。

如果傳送電子郵件訊息或呼叫器通知發生失敗,此失敗會在 SQL Server Agent 服務錯誤記錄檔中報告。

權限

只有系統管理員 (sysadmin) 固定伺服器角色的成員,才能夠執行 sp_add_notification

範例

下列範例會加入指定警示 (Test Alert) 的電子郵件通知。

[!附註]

這個範例假設 Test Alert 已經存在,且 François Ajenstat 是有效的操作員名稱。

USE msdb ;
GO

EXEC dbo.sp_add_notification
 @alert_name = N'Test Alert',
 @operator_name = N'François Ajenstat',
 @notification_method = 1 ;
GO