Delete Job by Name
-
Posted on April 20, 2010 by Derek Dieter
-
3
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.
[cc lang=”sql”]
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
[/cc]
- Comments (RSS)
- Trackback
- Permalink
It would be nice to have a script to delete many jobs at once with a like statement.
Why the hell does Manag/Studio generate the script with the job_id…..
Thanks for the tip, extremely helpful!
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.
Thanks for the information.. Nice.