Looking for T-SQL scripts to delete a SQL Job

11,862

Solution 1

USE msdb;

GO

EXEC sp_delete_job
    @job_name = N'NightlyBackups' ;

GO

Solution 2

You're looking for sp_delete_job:

[srv].[master].[dbo].sp_delete_job @job_name = 'MyJob'

So this four part name only works with linked servers. Otherwise, you'll have to connect to the server, and run that command against it (with everything right of [dbo]..

Solution 3

It's worth noting that you can just use SSMS, choose the job, right-click and pick "Delete", and then use the Script button at the top of the dialog box to generate a script like the ones suggested here.

Share:
11,862
George2
Author by

George2

Updated on June 13, 2022

Comments

  • George2
    George2 almost 2 years

    If I know the database server name, instance name and the SQL Server job name, how to delete a SQL Server job by its name in a simple way? I am writing scripts which will be called by sqlcmd to delete SQL jobs.

    Appreciate if anyone could show me a sample? :-)

    thanks in advance, George

  • George2
    George2 almost 15 years
    How about just execute USE msdb ; GO EXEC sp_delete_job @job_name = $(Job name here); GO