SQL Server: How to Limit Number of Emails Sent by SQL Server Agent

jobssql serversql server 2014sql-server-agent

I use SQL Server agent notifications a lot for notifying of failed jobs. Usually, jobs run every hour so I don't mind getting a few emails if the job fails.

However, I want to run a job every minute now and leave it running. I really don't want to get 100s of emails if it fails for a few hours.

Can I set a limit on the number of emails SQL Server agent will send for a job?

Best Answer

This feature is already built into SQL Server. I had a similar situation and what I did was to change my code to use a custom error number, above 50000, and set up a new Alert, under SQL Server Agent|Alerts in Management Studio, with that custom error number. Under the Options section, there is a Delay between responses section that can be used to mitigate the volume of notifications per hour. I had my process monitoring every 10 seconds, but notifying every 5 minutes because I wanted to know when the critical situation started, but not be overwhelmed with alerts.