Skip to content
 

Delete Job by Name

When scripting out jobs using ssms (sql server management studio) the default script for a drop statement is to drop the job according to it’s job_id. This is not beneficial however when pushing code to different environments. Job_id’s are specific to the windows environment in which they are created. To get around this is easy however, you simply need to pass the @job_name parameter to the sp_delete_job stored procedure.

IF  EXISTS (SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = N'jobnamegoeshere')
EXEC sp_delete_job @job_name = N'jobnamegoeshere' , @delete_unused_schedule=1


Popular search terms:

3 Comments

  1. Saberi says:

    After Run Error :

    Server: Msg 14274, Level 16, State 1, Procedure sp_delete_job, Line 86
    Cannot add, update, or delete a job (or its steps or schedules) that originated from an MSX server.

    Thanks for help me.

  2. Ranjan says:

    Thanks for the information.. Nice.

post a comment OR Post Your Question on our ASK! Community!