# 更新警报设置
#### 操作场景
使用存储过程更新现有警报的设置。
#### 前提条件
成功连接RDS for SQL Server实例。通过SQL Server客户端连接目标实例，具体操作请参见[通过公网连接RDS for SQL Server实例](https://support.huaweicloud.com/usermanual-rds-mssql/rds_mssql_connect_06.html)。成功连接RDS for SQL Server实例。
#### 操作步骤
执行以下命令，更新现有警报的设置。
```
EXEC [msdb].[dbo].[rds_update_alert]
@name='name',
@new_name='new_name',
@message_id=message_id,
@severity=severity,
@enabled=enabled,
@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';
```
表1参数说明 
| 参数                           | 说明                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
|:---|:---|
| 'name'                       | 更新的警报名称。名称为sysname，无默认值。                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| 'new_name'                    | 警报新名称。该名称必须唯一。"new_name"的值为"sysname"，默认值为NULL。                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| message_id                   | 警报定义的新消息或错误号。通常message_id与sysmessages表中的错误号相对应。message_id的数据类型为int，默认值为NULL。仅当警报的严重级别设置为0时，才能使用消息ID。                                                                                                                                                                                                                                                                                                                                                                                             |
| severity                     | 警报定义的新严重级别 (从1到25)。发送具有指定严重性的Windows应用程序日志的任何SQL Server消息都将激活警报。严重性为int，默认值为NULL。仅当警报的消息ID设置为0时，才能使用严重性级别。                                                                                                                                                                                                                                                                                                                                                                                       |
| enabled                      | 指示警报的当前状态。enabled为tinyint，默认值为1（已启用）。 如果为0，则不启用警报，也不触发警报。                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| delay_between_responses      | 警报响应之间的等待时间（以秒为单位）。"delay_between_responses"的值为"int"，默认值为0，这意味着响应之间不等待（每次出现警报时都生成响应）。响应可以为下面的一种或两种形式： - 通过电子邮件或寻呼发送的一个或多个通知。  - 要执行的作业。 例如，当警报在短时间内重复产生时，通过设置该值就有可能避免发送重复的电子邮件。                                                                                                     |
| 'notification_message'       | 作为电子邮件、net send或寻呼通知的一部分发送给操作员的可选附加消息。"notification_message"的值为"nvarchar（512）"，默认值为NULL。指定notification_message可用于添加特别注释，如补救过程。                                                                                                                                                                                                                                                                                                                                                                  |
| include_event_description_in | 指定是否应该在通知消息SQL Server中包含Windows应用程序日志中的错误说明。其数据值为tinyint，默认值为NULL，可以是下列值中的一个或多个。 - 值为0，表示无。  - 值为1，电子邮件。  - 值为2，表示寻呼程序。  - 值为4，表示net send。  - 值为7，表示All。   |
| 'database'                  | 必须发生错误才能触发警报的数据库。如果未提供数据库，则会触发警报，而不考虑错误发生的位置。数据库为sysname。不允许用方括号 (\[ \]) 将名称括起来。默认值为NULL。                                                                                                                                                                                                                                                                                                                                                                                                        |
| 'event_description_keyword'   | 必须在错误消息日志中的错误说明中找到的字符序列。可以使用Transact-SQL LIKE表达式模式匹配字符。"event_description_keyword"的值为"nvarchar (100) "，默认值为NULL。此参数适用于筛选对象名称 (例如, % customer_table% )。                                                                                                                                                                                                                                                                                                                                          |
| job_id                       | 作业标识号。"job_id"的值为"uniqueidentifier", 默认值为NULL。如果指定了job_id , 则必须省略job_name。                                                                                                                                                                                                                                                                                                                                                                                                                       |
| 'job_name'                   | 为响应此警报而执行的作业的名称。"job_name"的值为"sysname"，默认值为NULL。如果指定了job_name，则必须省略job_id。                                                                                                                                                                                                                                                                                                                                                                                                                        |
| occurrence_count             | 重置警报发生的次数。"occurrence_count"的值为"int"，默认值为NULL，且只能设置为0。                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| count_reset_date             | 重置上一次重置发生计数的日期。"count_reset_date"的值为"int"，默认值为NULL。                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| count_reset_time             | 重置上一次重置发生计数的时间。"count_reset_time"的值为"int"，默认值为NULL。                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| last_occurrence_date          | 重置警报上一次发生的日期。"last_occurrence_date"的值为"int"，默认值为NULL，且只能设置为0。                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| last_occurrence_time         | 重置警报上一次发生的时间。"last_occurrence_time"的值为"int"，默认值为NULL，且只能设置为0。                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| last_response_date             | 重置SQLServerAgent服务上一次响应警报的日期。"last_response_date"的值为"int"，默认值为NULL，且只能设置为0。                                                                                                                                                                                                                                                                                                                                                                                                                       |
| last_response_time          | 重置SQLServerAgent服务上一次响应警报的时间。"last_response_time"的值为"int"，默认值为NULL，且只能设置为0。                                                                                                                                                                                                                                                                                                                                                                                                                      |
| raise_snmp_trap               | 保护。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| 'performance_condition'       | 以 "itemcomparatorvalue" 格式表示的值。"performance_condition"的默认值为"nvarchar（512）"，默认值为NULL。其中包含这些元素： - 格式元素为项，表示性能对象、性能计数器或计数器的命名实例。  - 格式元素为Comparator，表示以下运算符之一： \>、\< 或 =。  - 格式元素为ReplTest1，表示计数器的数值。                                                                        |
| 'category'                   | 警报类别的名称。category的类型为sysname，默认值为NULL。                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| 'wmi_namespace'              | 要查询事件的WMI命名空间。"wmi_namespace"的值为"sysname"，默认值为NULL。                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| 'wmi_query'                  | 指定警报的WMI事件的查询。"wmi_query"的值为"nvarchar（512）"，默认值为NULL。                                                                                                                                                                                                                                                                                                                                                                                                                                           |
   
执行成功后，系统将会如下提示：
```
Commands completed successfully.
```
#### 示例
![](https://support.huaweicloud.com/usermanual-rds-mssql/zh-cn_image_0000002249955021.png)
回显如下所示：
![](https://support.huaweicloud.com/usermanual-rds-mssql/zh-cn_image_0000002214915166.png)
