Skip to content

Latest commit

 

History

History
115 lines (77 loc) · 3.95 KB

File metadata and controls

115 lines (77 loc) · 3.95 KB
title sp_start_job (Transact-SQL)
description sp_start_job instructs the SQL Server Agent to execute a job immediately.
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_start_job
sp_start_job_TSQL
helpviewer_keywords
sp_start_job
dev_langs
TSQL
monikerRange >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current

sp_start_job (Transact-SQL)

[!INCLUDE sql-asdbmi]

Instructs [!INCLUDE ssNoVersion] Agent to execute a job immediately.

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

Syntax

sp_start_job
    [ [ @job_name = ] N'job_name' ]
    [ , [ @job_id = ] 'job_id' ]
    [ , [ @error_flag = ] error_flag ]
    [ , [ @server_name = ] N'server_name' ]
    [ , [ @step_name = ] N'step_name' ]
    [ , [ @output_flag = ] output_flag ]
[ ; ]

Arguments

[ @job_name = ] N'job_name'

The name of the job to start. @job_name is sysname, with a default of NULL.

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

[ @job_id = ] 'job_id'

The identification number of the job to start. @job_id is uniqueidentifier, with a default of NULL.

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

[ @error_flag = ] error_flag

[!INCLUDE ssInternalOnly]

[ @server_name = ] N'server_name'

The target server on which to start the job. @server_name is sysname, with a default of NULL. @server_name must be one of the target servers to which the job is currently targeted.

[ @step_name = ] N'step_name'

The name of the step at which to begin execution of the job. @step_name is sysname, with a default of NULL. Applies only to local jobs.

[ @output_flag = ] output_flag

[!INCLUDE ssInternalOnly]

Return code values

0 (success) or 1 (failure).

Result set

None.

Remarks

This stored procedure is in the msdb database.

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

[!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.

Members of SQLAgentUserRole and SQLAgentReaderRole can only start jobs that they own. Members of SQLAgentOperatorRole can start all local jobs, including jobs that are owned by other users. Members of sysadmin can start all local and multiserver jobs.

Examples

The following example starts a job named Weekly Sales Data Backup.

USE msdb;
GO

EXECUTE dbo.sp_start_job N'Weekly Sales Data Backup';
GO

Related content