Click to Rate and Give Feedback
TechNet
TechNet Library
SQL Server
SQL Server 2008
Database Engine
Technical Reference
 sp_start_job (Transact-SQL)

  Switch on low bandwidth view
Collapse All/Expand All Collapse All
Other versions are also available for the following:
SQL Server 2008 Books Online (October 2009)
sp_start_job (Transact-SQL)

Instructs SQL Server Agent to execute a job immediately.

Topic link icon Transact-SQL Syntax Conventions

sp_start_job 
     {   [@job_name =] 'job_name'
       | [@job_id =] job_id }
     [ , [@error_flag =] error_flag]
     [ , [@server_name =] 'server_name']
     [ , [@step_name =] 'step_name']
     [ , [@output_flag =] output_flag]
[ @job_name = ] 'job_name'

The name of the job to start. Either job_id or job_name must be specified, but both cannot be specified. job_name is sysname, with a default of NULL.

[ @job_id = ] job_id

The identification number of the job to start. Either job_id or job_name must be specified, but both cannot be specified. job_id is uniqueidentifier, with a default of NULL.

[ @error_flag = ] error_flag

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

[ @server_name = ] 'server_name'

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

[ @step_name = ] 'step_name'

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

[ @output_flag = ] output_flag

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

0 (success) or 1 (failure)

None

This stored procedure is in the msdb database.

By default, members of the sysadmin fixed server role can execute this stored procedure. 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 those 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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker