sp_start_job (Transact-SQL)

Applies to: SQL Server Azure SQL Managed Instance

Instructs SQL Server Agent to execute a job immediately.

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

Identified for informational purposes only. Not supported. Future compatibility is not guaranteed.

[ @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

Identified for informational purposes only. Not supported. Future compatibility is not guaranteed.

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

This stored procedure is owned by the db_owner role. You can grant EXECUTE permissions for any user, but these permissions may be overridden during a SQL Server upgrade.

Other users must be granted one of the following SQL Server 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

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