Share via


sp_start_job (Transact-SQL)

Instructs SQL Server Agent to execute a job immediately.

Syntax

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]

Arguments

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

Return Code Values

0 (success) or 1 (failure)

Result Sets

None

Remarks

This stored procedure is in the msdb database.

Permissions

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.

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

See Also

Reference

sp_delete_job (Transact-SQL)
sp_help_job (Transact-SQL)
sp_stop_job (Transact-SQL)
sp_update_job (Transact-SQL)
System Stored Procedures (Transact-SQL)

Help and Information

Getting SQL Server 2005 Assistance