Reputation: 45771
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
Upvotes: 6
Views: 15623
Reputation: 1104
USE msdb;
GO
EXEC sp_delete_job
@job_name = N'NightlyBackups' ;
GO
Upvotes: 17
Reputation: 15849
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.
Upvotes: 2
Reputation: 95133
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].
.
Upvotes: 3