Skip to content

Latest commit

 

History

History
100 lines (74 loc) · 4.04 KB

File metadata and controls

100 lines (74 loc) · 4.04 KB
title sp_start_job (Transact-SQL) | Microsoft Docs
ms.custom
ms.date 03/14/2017
ms.prod sql
ms.prod_service database-engine
ms.reviewer
ms.technology system-objects
ms.topic language-reference
f1_keywords
sp_start_job
sp_start_job_TSQL
dev_langs
TSQL
helpviewer_keywords
sp_start_job
ms.assetid 8a91df6a-eb84-4512-9a17-4a6e32a9538a
author stevestein
ms.author sstein

sp_start_job (Transact-SQL)

[!INCLUDEtsql-appliesto-ss2008-xxxx-xxxx-xxx-md]

Instructs [!INCLUDEssNoVersion] Agent to execute a job immediately.

Topic link icon Transact-SQL Syntax Conventions

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 [!INCLUDEssInternalOnly]

[ @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 [!INCLUDEssInternalOnly]

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 [!INCLUDEssNoVersion] 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

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)