Categories
Scripts

Trigger to Check Job failures

I was trying to find a alert which could fire immediately upon any of the job failure in the server to send an email. Unfortunately I couldn’t find any the alert related to this. So I thought of writing a DML trigger which should fire immediately when an entry is inserted in sysjobhistory table on msdb database. The next step is that the trigger should send a mail when there is failure in the job, hence Ive used run_status column in the table, as all the DBAs know when this column has a value 0 then it states the job has been failed. Ive tried this script in SQL Server greater than version 2000 however its not working on it. This script works only on SQL Server 2000, still some of them are still working on SQL 2000 so I thought this script has still value. This DML trigger will send an email upon any of the job failure.