问题
I have a Job setup in SQL Server 2008 which sends a notification email to one operator when the job fails.
Question: Is it possible to setup a notification email being sent to multiple operators for that specific job?
I believe a possible workaround for this is to create lots of alerts for the database for each given severity but I was hoping that there was a more concise way to do this. If I were to go this route, what severity errors would likely be triggered from a failed job? (I don't think I would require all 25 for something like that)
Can this be done through sql command to add more operators to notify on failure? Through the UI you are only able to choose a single operator it seems.
回答1:
Question: Is it possible to setup a notification email being sent to multiple operators for that specific job?
I don't believe this is possible.
Certainly looking at the structure of [msdb].[dbo].[sysjobs]
the various operator_id
columns are in this table itself which would support the idea that 1 to many is not possible.
But some alternatives
- You could create a new operator with the semi colon delimited list of email addresses. Looking at the definition of
sysoperators
this is good for strings that can fit innvarchar(100)
- if you need to exceed that you could probably set up an email distribution group on exchange or whatever.
回答2:
If the intention is that multiple people in your organization should be notified if a job fails, you can change the email address of the operator to include multiple mailboxes by separating each mailbox with a semicolon.
I'm assuming your notified operator is called JobWatcher:
EXECUTE msdb.dbo.sp_update_operator
@name = N'JobWatcher',
@email_address = N'person1@company.org;person2@company.org';
Now person1@company.org and person2@company.org will receive mail when the job fails.
回答3:
The simplest method i use to notify multiple "OPERATORS"
on "JOB FAILURE"
is to:
In SSMS>SQL Server Agent>Operators
create a new OPERATOR
or EDIT
existing and add additional email addresses separated by ;
in "E-mail name:"
box.
回答4:
The best practice would be to create a group on your mail server, send the notifications to the group and then control the number of recipients from the mail server.
回答5:
So this is what I came up with as a workaround if the intention is that multiple people in your organization should be notified if a job fails and a different group of multiple people for successes.
You will notice the Steps 1-3 are the normal tasks that the schedule job is uses for as you would do for your task. There can as many steps as needed before these but the last step (Step 3) of the process need to break “On Success” and “On Failure” to go into separate emails. Also all “On Failures” need to continue to your “Failure Email” as highlighted below. So the Failure group gets there emails and the job will still fail for the historical records.
You will see the option to change the direction of the “On success action” and “On Failure action” in the Advanced tab of the Job steps.
Failure Email Step -General Property
Failure Email Step -Advance Property
Success Email Step -General Property
Success Email Step -Advance Property
For others in need help. Notify multiple operators with difference results
回答6:
Please use below script to increase the character length of email address.
USE mdsdb
GO
ALTER TABLE sysoperators
ALTER column email_address NVARCHAR(2000);
来源:https://stackoverflow.com/questions/7431582/sql-server-agent-job-notify-multiple-operators-on-failure