title | description | author | ms.author | ms.reviewer | ms.date | ms.service | ms.subservice | ms.topic | f1_keywords | helpviewer_keywords | dev_langs | monikerRange | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sp_start_job (Transact-SQL) |
sp_start_job instructs the SQL Server Agent to execute a job immediately. |
markingmyname |
maghan |
randolphwest |
08/22/2024 |
sql |
system-objects |
reference |
|
|
|
>=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current |
[!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
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 ]
[ ; ]
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.
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.
[!INCLUDE ssInternalOnly]
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.
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.
[!INCLUDE ssInternalOnly]
0
(success) or 1
(failure).
None.
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.
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