sp_add_alert (języka Transact-SQL)

sp_add_alert [ @name = ] '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_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' ]

Argumenty

  • [ @name = ] 'name'
    Nazwa alert.Nazwa jest wyświetlana w wiadomości e-mail lub pager wysłanych w odpowiedzi na alert.It must be unique and can contain the percent (%) character.name is sysname, with no default.

  • [ @message_id = ] message_id
    Liczba błędów wiadomości definiuje alert.(Zazwyczaj odpowiadający mu błąd numer sysmessages tabela.) message_id jest int, z domyślnego programu 0.Jeśli severity Służy do definiowania alert, message_id musi być 0 lub wartość NULL.

    Uwaga

    Tylko sysmessages błędy zapisane w dzienniku aplikacji systemu Microsoft Windows może spowodować, że alert ma być wysłany.

  • [ @severity = ] severity
    Poziom ważności (z 1 through 25) definiuje alert.Any SQL Server message stored in the sysmessages table sent to the Microsoft Windows application log with the indicated severity causes the alert to be sent.severity is int, with a default of 0.Jeśli message_id Służy do definiowania alert, severity musi być 0.

  • [ @enabled = ] enabled
    Indicates the current status of the alert.enabled is tinyint, with a default of 1 (enabled).Jeśli 0, alert nie jest włączone i nie uruchomienie.

  • [ @delay_between_responses = ] delay_between_responses
    The wait period, in seconds, between responses to the alert.delay_between_responsesis int, with a default of 0, which means there is no waiting between responses (each occurrence of the alert generates a response).Odpowiedź może znajdować się w jedną lub obie te formy:

    • Jeden lub więcej powiadomienia wysyłane za pośrednictwem poczty e-mail lub pager.

    • zadanie do wykonać.

    Ustawiając tę wartość, istnieje możliwość zapobiec, na przykład niechciane wiadomości e-mail z wysyłane, gdy często pojawia się alert w krótkim czasie.

  • [ @notification_message = ] 'notification_message'
    Is an optional additional message sent to the operator as part of the e-mail, net send, or pager notification.notification_message is nvarchar(512), with a default of NULL.Określanie notification_message jest przydatne przy dodawaniu specjalne uwagi, takie jak procedury zaradczych.

  • [ @include_event_description_in = ] include_event_description_in
    Is whether the description of the SQL Server error should be included as part of the notification message.include_event_description_inis tinyint, with a default of 5 (e-mail and net send), and can have one or more of these values combined with an OR logical operator.

    Important noteImportant Note:

    The Pager and net send options will be removed from SQL Server Agent in a future version of Microsoft SQL Server.Należy unikać stosowania tych funkcji w nowej pracy rozwoju i zaplanować do modyfikowania aplikacji korzystających aktualnie z tych funkcji.

    Wartość

    Description

    0 (domyślnie)

    None

    1

    Wiadomości e-mail

    2

    Pager

    4

    polecenie net send

  • [ @database_name = ] 'database'
    Bazy danych, w którym błędu musi przypadać na alert uruchomienie.If databaseis not supplied, the alert fires regardless of where the error occurred.database is sysname.Zmiana ochrony przedDomyślną wartością jest NULL.

  • [ @event_description_keyword = ] 'event_description_keyword_pattern'
    Sekwencja znaków, który opis SQL Server Błąd musi być tak jak. Transact-SQL LIKE expression pattern-matching characters can be used.event_description_keyword_pattern is nvarchar(100), with a default of NULL.Ten parametr jest użyteczny do filtrowania (na przykład, nazwy obiektów customer_table %).

  • [ @job_id = ] job_id
    The job identification number of the job to run in response to this alert.job_id is uniqueidentifier, with a default of NULL.

  • [ @job_name = ] 'job_name'
    The name of the job to be executed in response to this alert.job_nameis sysname, with a default of NULL.

    Uwaga

    Albo job_id lub job_name musi być określona, ale nie może być jednocześnie określone.

  • [ @raise_snmp_trap = ] raise_snmp_trap
    Not implemented in SQL Server version 7.0.raise_snmp_trap is tinyint, with a default of 0.

  • [ @performance_condition = ] 'performance_condition'
    Is a value expressed in the format 'itemcomparatorvalue'.performance_condition is nvarchar(512) with a default of NULL, and consists of these elements.

    Formatowanie elementu

    Description

    Item

    Obiekt wydajności, licznik wydajności lub wystąpienie nazwane tego licznika

    Comparator

    Jeden z tych operatorów: >, <, or =

    Value

    Wartość liczbowa licznika

  • [ @category_name = ] 'category'
    The name of the alert category.category is sysname, with a default of NULL.

  • [ @ wmi_namespace= ] "wmi_namespace'
    The WMI namespace to query for events.wmi_namespace is sysname, with a default of NULL.Obsługiwane są tylko obszary nazw na serwerze lokalnym.

  • [ @ wmi_query= ] "wmi_query'
    The query that specifies the WMI event for the alert.wmi_query is nvarchar(512), with a default of NULL.

Wartości kodów powrotnych

0 (sukces) lub 1 (brak)

Zestawy wyników

None

Remarks

sp_add_alert musi być uruchamiane msdb bazy danych.

Są to okoliczności, w których błędy/komunikaty generowane przez SQL Server i SQL Server aplikacje są wysyłane do dziennika aplikacji systemu Windows i w związku z tym można podnieść alertów:

  • Wskaźnik ważności, 19 lub nowszej sysmessages errors

  • Instrukcja RAISERROR, wszystkie wywoływane ze składnią WITH dziennik

  • Wszystkie sysmessages błąd zmodyfikowanych lub utworzonych za pomocą sp_altermessage

  • Każde zdarzenie logowany przy użyciu xp_logevent

SQL Server Management Studio zapewnia łatwy, graficzny sposób zarządzania systemem całego alert ing i jest zalecanym sposobem skonfigurowania alert infrastruktury.

Jeśli alert nie działa poprawnie, sprawdź, czy:

  • The SQL Server Agent usługa is running.

  • Zdarzenie pojawiły się w dzienniku aplikacji systemu Windows.

  • Alert jest włączona.

  • Zdarzenia generowane z xp_logevent występują w głównej bazie danych.Dlatego też xp_logevent nie spowoduje wyzwolenia alertu, chyba że @ nazwa_bazy_danych alertu jest "główny" lub wartość NULL.

Uprawnienia

Domyślnie tylko członkowie sysadmin roli serwera stałe mogą być wykonać sp_add_alert.

Przykłady

W następującym przykładzie dodano alert (test alert), który uruchamia Back up the AdventureWorks Database zadanie w momencie uruchomienia.

Uwaga

W tym przykładzie założono, że wiadomość 55001 oraz Back up the AdventureWorks Database zadanie już istnieje. W przykładzie jest wyświetlana tylko w celach opisowy.

USE msdb ;
GO

EXEC dbo.sp_add_alert
    @name = N'Test Alert',
    @message_id = 55001, 
   @severity = 0, 
   @notification_message = N'Error 55001 has occurred. The database will be backed up...', 
   @job_name = N'Back up the AdventureWorks Database' ;
GO