學習使用SQL Server代理創建警報的最簡單方法

SQL Server警報提供全天候錯誤通知

SQL Server代理允許在發生異常情況時自動通知數據庫管理員。 這種強大的警報機制可以實現24小時數據庫性能監控,無需配備24小時運營中心。

定義警報的一般要求

為了定義警報,您需要某些基本信息,包括:

循序漸進的SQL Server警報設置

這些說明適用於SQL Server 2005及更新版本。

  1. 打開SQL Server Management Studio並連接到要創建警報的數據庫服務器。
  2. 單擊文件夾左側的“ + ”圖標以展開SQL Server代理文件夾。
  3. 右鍵單擊Alerts文件夾並從彈出菜單中選擇New Alert
  4. 名稱文本框中輸入警報的描述性名稱。
  5. 從下拉菜單中選擇警報的類型。 您的選擇是SQL Server性能狀況,如CPU負載和可用磁盤空間, SQL Server事件 (如致命錯誤,語法錯誤和硬件問題)以及Windows Management Instrumentation(WMI)事件。
  6. 提供SQL Server請求的任何警報特定的詳細信息,例如事件報告中包含的特定文本以及性能狀況警報的參數。
  7. 單擊新建警報窗口的選擇頁面窗格中的響應圖標。
  8. 如果您想在發生警報時執行SQL Server代理作業,請單擊執行作業複選框並從下拉菜單中選擇作業。
  9. 如果要在發生警報時通知數據庫操作員,請單擊通知操作員複選框,然後從網格中選擇操作員和通知類型。
  1. 單擊確定以創建警報。

使用Transact-SQL添加警報

從SQL Server 2008開始,您還可以使用Transact-SQL添加警報。 使用Microsoft的這種語法:

sp_add_alert [@name =] [,[@message_id =] message_id] [,[@severity =] severity] [,[@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_pattern'] [,{[@job_id =] job_id | [@job_name =]'job_name'}] [,[@raise_snmp_trap =] raise_snmp_trap] [,[@ performance_condition =]'performance_condition'] [,[@category_name =]'category'] [,[@wmi_namespace =]'wmi_namespace '] [,[@wmi_query =]'wmi_query']