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
To delete a jobExpand SQL Server Agent, expand Jobs, right-click the job you want to delete, and then click Delete. In the Delete Object dialog box, confirm that the job you intend to delete is selected. Click OK.
Using SQL Server Management StudioExpand SQL Server Agent, and then expand Jobs. Right-click a job and click View history. In the Log File Viewer, select the job for which you want to clear history, and then do one of the following: Click Delete, and then click Delete all history in the Delete History dialog.
Syntax. DELETE FROM table_name WHERE [condition];
USE msdb;
GO
EXEC sp_delete_job
@job_name = N'NightlyBackups' ;
GO
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].
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With