• Love the script but wanted to be able to deploy this quicker. The final step of creating an alert I simply switched to TSQL and it achieves the same result without having to use the wizard:

    --THIS GETS RUN AFTER THE JOB IS CREATED AND WILL CREATE THE ALERT

    USE [msdb]

    GO

    declare

    @jobid uniqueidentifier

    set @jobid = isnull((select job_id from msdb.dbo.sysjobs where name = 'Deadlock Job'),'00000000-0000-0000-0000-000000000000')

    set @jobid = LTRIM(rtrim(@jobid))

    IF @jobid = '00000000-0000-0000-0000-000000000000'

    BEGIN

    RAISERROR('The deadlock job could not be found. Aborting!', 16, 1)

    RETURN

    END

    IF EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = N'DeadlockAlert')

    BEGIN

    RAISERROR('The alert already exists. Aborting!',16,1)

    RETURN

    END

    EXEC msdb.dbo.sp_add_alert @name=N'DeadlockAlert',

    @message_id=0,

    @severity=0,

    @enabled=1,

    @delay_between_responses=60,

    @include_event_description_in=0,

    @category_name=N'[Uncategorized]',

    @performance_condition=N'SQLServer:Locks|Number of Deadlocks/sec|_Total|>|0',

    @job_id= @jobid

    GO