Skip to content

Latest commit

 

History

History
111 lines (75 loc) · 3.71 KB

File metadata and controls

111 lines (75 loc) · 3.71 KB
title sp_delete_jobstep (Transact-SQL)
description Removes a job step from a job in the SQL Server Agent service.
author markingmyname
ms.author maghan
ms.reviewer randolphwest
ms.date 06/23/2025
ms.service sql
ms.subservice system-objects
ms.topic reference
f1_keywords
sp_delete_jobstep
sp_delete_jobstep_TSQL
helpviewer_keywords
sp_delete_jobstep
dev_langs
TSQL
monikerRange >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current

sp_delete_jobstep (Transact-SQL)

[!INCLUDE sql-asdbmi]

Removes a job step from a job in the [!INCLUDE ssnoversion-md] Agent service.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

sp_delete_jobstep
    [ [ @job_id = ] 'job_id' ]
    [ , [ @job_name = ] N'job_name' ]
    , [ @step_id = ] step_id
[ ; ]

Arguments

[ @job_id = ] 'job_id'

The identification number of the job from which the step will be removed. @job_id is uniqueidentifier, with a default of NULL.

Either @job_id or @job_name must be specified; both can't be specified.

[ @job_name = ] N'job_name'

The name of the job from which the step will be removed. @job_name is sysname, with a default of NULL.

Either @job_id or @job_name must be specified; both can't be specified.

[ @step_id = ] step_id

The identification number of the step being removed. @step_id is int, with no default.

Return code values

0 (success) or 1 (failure).

Result set

None.

Remarks

Removing a job step automatically updates the other job steps that reference the deleted step.

For more information about the steps associated with a particular job, run sp_help_jobstep.

Note

Calling sp_delete_jobstep with a @step_id value of zero deletes all job steps for the job.

SQL Server Management Studio provides an easy, graphical way to manage jobs, and is the recommended way to create and manage the job infrastructure.

This stored procedure shares the name of sp_delete_jobstep with a similar object for the Azure Elastic Jobs service for Azure SQL Database. For information about the elastic jobs version, see jobs.sp_delete_jobstep (Azure Elastic Jobs).

Permissions

[!INCLUDE msdb-execute-permissions]

Other users must be granted one of the following [!INCLUDE ssNoVersion] Agent fixed database roles in the msdb database:

  • SQLAgentUserRole
  • SQLAgentReaderRole
  • SQLAgentOperatorRole

For details about the permissions of these roles, see SQL Server Agent Fixed Database Roles.

Only members of sysadmin can delete a job step that is owned by another user.

Examples

The following example removes job step 1 from the job Weekly Sales Data Backup.

USE msdb;
GO

EXECUTE dbo.sp_delete_jobstep
    @job_name = N'Weekly Sales Data Backup',
    @step_id = 1;
GO

Related content