更新现有警报的设置。
语法
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_name'] 
     [ , [ @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 时,才能使用消息 ID。
- [ @severity =] severity
 警报定义的新严重级别(从 1 到 25)。 任何发送给 Windows 应用程序日志的具有指定严重级别的 Microsoft SQL Server 消息都会激活警报。severity 的数据类型为 int,默认值为 NULL。 仅当警报的消息 ID 设置为 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 - 网络发送 - 7 - 全部 
- [ @database_name =] 'database_name'
 数据库名,只有该数据库中发生错误时,才能激发警报。database_name 的数据类型为 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)