none
How to execute Sql Server Agent job from Trigger

    Question

  • Hi All,

       I want to execute sql server agent job from update trigger is there is any work around or useful links for this?  Please let me know how to achive this..

    Thanks in Advance
    Lakshman
    Monday, November 23, 2009 7:21 AM

Answers

  • You can define a trigger like below to execute a job

    CREATE TRIGGER TriggerName
    ON TableName
    AFTER INSERT, UPDATE, DELETE
    AS
       EXEC msdb..sp_start_job
            @job_name = 'JobName';
    GO
    Rahul Kumar, MCTS, India, http://sqlserversolutions.blogspot.com/
    • Marked as answer by Murty Addanki Monday, November 23, 2009 8:26 AM
    Monday, November 23, 2009 7:40 AM

All replies

  • You can define a trigger like below to execute a job

    CREATE TRIGGER TriggerName
    ON TableName
    AFTER INSERT, UPDATE, DELETE
    AS
       EXEC msdb..sp_start_job
            @job_name = 'JobName';
    GO
    Rahul Kumar, MCTS, India, http://sqlserversolutions.blogspot.com/
    • Marked as answer by Murty Addanki Monday, November 23, 2009 8:26 AM
    Monday, November 23, 2009 7:40 AM
  • Inside the Trigger creation statement use sp_start_job with all the parameters it requires.
    Thanks, Bharani M - Please mark the post as answered if it answers your question. - Please vote the post as Helpful if you find the post as helpful.
    • Proposed as answer by Bharani 3010 Monday, November 23, 2009 8:42 AM
    Monday, November 23, 2009 8:25 AM