What are you looking for ?
Home » » Trigger fire an Agent job

Trigger fire an Agent job

{[['']]}

Execute Sql Server Agent job from Trigger

Script

CREATE TRIGGER TriggerName
ON TableName
AFTER INSERT, UPDATE, DELETE
AS
EXEC msdb..sp_start_job
@job_name = 'JobName';
GO
Inside the Trigger creation statement you can use sp_start_job with all the Arguments you need.

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 isuniqueidentifier, 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.
Share this article :

Post a Comment

Flag Counter

Social Profile

 
Copyright x 2011. By Wael Medhat - All Rights Reserved