Results 1 to 6 of 6

Thread: Update Trigger

  1. #1
    Join Date
    Sep 2003
    Posts
    7

    Unanswered: Update Trigger

    Hi,

    If I have a situation where a particular SQL statement updates three records on a table and there is an Update trigger defined on the table, then how many times will the trigger fire - three times or one time.

    Thanks in advance.
    Raj

  2. #2
    Join Date
    Nov 2003
    Location
    Edinburgh
    Posts
    149

    Re: Update Trigger

    The trigger will fire once.


    The update of three records is considered a single update statement not three seperate updates and hence the trigger will fire only once.

    If you throw three updates in a row at the tabe then the trigger will fire three times.

    Cheers

  3. #3
    Join Date
    Jan 2004
    Posts
    49
    2aldo_2003:
    The disputable statement.... Depends on the trigger's code...

  4. #4
    Join Date
    Nov 2003
    Location
    Edinburgh
    Posts
    149

    Talking

    this is indeed correct buser :

    I was assuming the default trigger action is which is an after trigger which will perform as I have stated

    buser: would you like to enlighten rajk on the instead of trigger

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    "Depends on the trigger's code"???

    How does an update trigger's code govern how often it fires? Unless you are talking about recursion....

    rajk, the trigger will fire once, but if you need to handle each updated record separately you will find the updated records in a virtual table called "inserted", with the exact same table structure as your updated table. You can select, join, or run cursors on this virtual table just like any permanent table to enable the logic you need.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  6. #6
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Originally posted by blindman
    "Depends on the trigger's code"???

    How does an update trigger's code govern how often it fires? Unless you are talking about recursion....

    rajk, the trigger will fire once, but if you need to handle each updated record separately you will find the updated records in a virtual table called "inserted", with the exact same table structure as your updated table. You can select, join, or run cursors on this virtual table just like any permanent table to enable the logic you need.
    Easy...

    And yes he's right.....

    How a trigger is not dependant on anything...

    UPDATE myTable99

    Will fire a rtigger once on myTable99 regardless of the number of rows affacted...
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •