sp_add_alert (Transact-SQL)

Bir uyarı oluşturur.

Topic link iconTransact-SQL sözdizimi kuralları

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' ]

Bağımsız değişkenler

  • [ @name = ] 'name'
    uyarı adı.uyarı yanıt olarak gönderilen e-posta veya çağrı cihazı iletisi adı görüntülenir.It must be unique and can contain the percent (%) character.name is sysname, with no default.

  • [ @message_id = ] message_id
    uyarı tanımlayan iletinin hata numarası.(Genellikle bir hata numaraya karşılık Sysmessages tablo.) message_id olan int, varsayılan değeri ile 0.If severity Uyarı, tanımlamak için kullanılır message_id olmalıdır 0 veya NULL.

    Not

    veritabanı Sysmessages hatalar için Microsoft Windows Uygulama günlüğüne bir uyarı gönderilmesini neden olabilir.

  • [ @severity = ] severity
    Önem düzeyini ( 1 through 25) uyarı tanımlar.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.If message_id Uyarı, tanımlamak için kullanılır severity olmalıdır 0.

  • [ @enabled = ] enabled
    Indicates the current status of the alert.enabled is tinyint, with a default of 1 (enabled).If 0, uyarı etkinleştirilmediği ve yangın değil.

  • [ @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).Yanıtta, ya da ikisinden birini bu formlar olabilir:

    • çağrı cihazı veya e-posta ile gönderilen bir veya daha fazla bildirimler.

    • Yürütülecek BIR iş.

    Bu değeri ayarlayarak, örneğin, uyarı kısa bir saat içinde sürekli oluştuğunda gönderilen istenmeyen e-posta iletilerinin engellenmesine olasıdır.

  • [ @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.Belirtme notification_message remedial yordamlar gibi özel notlar eklemek için kullanışlıdır.

  • [ @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.Bu özellikler, yeni iş geliştirme kullanmaktan kaçının ve bu özellikleri kullanan uygulamalar değiştirmek planlama.

    Değer

    Açıklama

    0 (varsayılan)

    None

    1

    E-posta

    2

    Çağrı cihazı

    4

    net send

  • [ @database_name = ] 'database'
    Veritabanı hata uyarı harekete yürütülmelidir.If databaseis not supplied, the alert fires regardless of where the error occurred.database is sysname.Işlev türüNULL varsayılan değerdir.

  • [ @event_description_keyword = ] 'event_description_keyword_pattern'
    Sırasını, karakter açıklamasını SQL Server gibi hata olması gerekir. Transact-SQL LIKE expression pattern-matching characters can be used.event_description_keyword_pattern is nvarchar(100), with a default of NULL.Bu parametre, nesne adları (örneğin, süzmek için kullanışlıdır 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.

    Not

    Her iki job_id veya job_name belirtilmiş olması gerekir, ancak her ikisi de belirtilemiyor.

  • [ @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.

    Biçim öğesi

    Açıklama

    Item

    Bir performans nesnesi, performans sayacı veya sayacı adlandırılmış örnek

    Comparator

    Bu işleçlerden birini: >, <, or =

    Value

    Sayaç sayısal bir değer

  • [ @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.Yalnızca yerel sunucuda ad boşlukları desteklenir.

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

Dönüş Kodu Değerleri

0 (başarılı) veya 1 (hata)

Sonuç Kümeleri

None

Remarks

sp_add_alert çalıştırılmalıdır.msdb veritabanıdır.

Oluşturulan hangi hataları/iletileri durumlarda bunlar SQL Server ve SQL Server uygulamalar, Windows Uygulama günlüğüne gönderilir ve bu nedenle uyarıları yükseltebilirsiniz:

  • 19 Veya yüksek önem derecesi Sysmessages errors

  • WITH LOG sözdizimiyle çalıştırılan herhangi bir RAISERROR deyim

  • Tüm Sysmessages kullanılarak oluşturulan veya değiştirilirken hatasp_altermessage

  • Kullanarak oturum açmış herhangi bir olayı xp_logevent

SQL Server Management Studio Tüm alerting sistem yönetmek için kolay ve grafiksel bir yol sunar ve bir uyarı Altyapısı'nı yapılandırmak için önerilen yöntemdir.

Uyarı düzgün çalışmıyorsa, denetleme mi:

  • The SQL Server Agent hizmet is running.

  • Olay, Windows Uygulama günlüğüne görüntülendi.

  • Uyarı: etkin.

  • Ile üretilen olaylar xp_logevent ana veritabanında oluşur.Bu nedenle, xp_logevent sürece uyarı tetiklemez @ veritabanı_adı Uyarı: olur.'ana' veya NULL.

İzinler

Varsayılan olarak, yalnızca üyeleri sysadmin sabit sunucu rolü çalıştırabilirsinizsp_add_alert.

Örnekler

Aşağıdaki örnek, çalışan (sınama Uyarısı) uyarı ekler Back up the AdventureWorks Database harekete geçirildi, iş.

Not

Bu örnek, varsayar 55001 iletinin ve Back up the AdventureWorks Database iş zaten mevcut. Örneğin, yalnızca görsel amacıyla gösterilir.

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