Skip to content

Latest commit

 

History

History
100 lines (70 loc) · 2.93 KB

sp-add-notification-transact-sql.md

File metadata and controls

100 lines (70 loc) · 2.93 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs
sp_add_notification (Transact-SQL)
Sets up a notification for an alert.
MashaMSFT
mathoma
randolphwest
06/02/2023
sql
system-objects
reference
sp_add_notification_TSQL
sp_add_notification
sp_add_notification
TSQL

sp_add_notification (Transact-SQL)

[!INCLUDE SQL Server]

Sets up a notification for an alert.

Syntax

sp_add_notification [ @alert_name = ] 'alert' ,
    [ @operator_name = ] 'operator' ,
    [ @notification_method = ] notification_method
[ ; ]

Arguments

[ @alert_name = ] 'alert'

The alert for this notification. @alert_name is sysname, with no default.

[ @operator_name = ] 'operator'

The operator to be notified when the alert occurs. @operator_name is sysname, with no default.

[ @notification_method = ] notification_method

The method by which the operator is notified. @notification_method is tinyint, with no default. @notification_method can be one or more of these values combined with an OR logical operator.

Value Description
1 E-mail
2 Pager
4 net send

Return code values

0 (success) or 1 (failure).

Result set

None.

Remarks

sp_add_notification must be run from the msdb database.

[!INCLUDE ssManStudioFull] provides an easy, graphical way to manage the entire alerting system. Using [!INCLUDE ssManStudio] is the recommended way to configure your alert infrastructure.

To send a notification in response to an alert, you must first configure [!INCLUDE ssNoVersion] Agent to send mail.

If a failure occurs when sending an e-mail message or pager notification, the failure is reported in the [!INCLUDE ssNoVersion] Agent service error log.

Permissions

[!INCLUDE msdb-execute-permissions]

Examples

The following example adds an e-mail notification for the specified alert (Test Alert).

Note

This example assumes that Test Alert already exists and that François Ajenstat is a valid operator name.

USE msdb;
GO

EXEC dbo.sp_add_notification
    @alert_name = N'Test Alert',
    @operator_name = N'François Ajenstat',
    @notification_method = 1;
GO

Related content