Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for T-SQL scripts to delete a SQL Job

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

like image 398
George2 Avatar asked Aug 02 '09 16:08

George2


People also ask

How do you delete a SQL job?

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.

How do I delete a specific job history in SQL Server?

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.

Which SQL command is used to delete any statement?

Syntax. DELETE FROM table_name WHERE [condition];


2 Answers

USE msdb;

GO

EXEC sp_delete_job
    @job_name = N'NightlyBackups' ;

GO
like image 106
Sergey Olontsev Avatar answered Oct 06 '22 14:10

Sergey Olontsev


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]..

like image 38
Eric Avatar answered Oct 06 '22 15:10

Eric