sp_add_notification (Transact-SQL)

适用于:SQL Server

设置警报通知。

语法

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

参数

[ @alert_name = ] 'alert'

该通知的警报。 @alert_name为 sysname,无默认值。

[ @operator_name = ] 'operator'

警报发生时要通知的操作员。 @operator_namesysname,无默认值。

[ @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 代理以发送邮件。

如果在发送电子邮件或寻呼通知时出现故障,则该故障将被记录到 SQL Server 代理服务错误日志中。

权限

此存储过程由 db_owner 角色拥有。 你可以为任何用户授予 EXECUTE 权限,但这些权限可能会在 SQL Server 升级期间被重写。

示例

以下示例为指定的警报 (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