When do triggers fire and when don't they

后端 未结 4 2067
感动是毒
感动是毒 2021-02-20 16:54

Pretty general question regarding triggers in SQL server 2005.

In what situations are table triggers fired and what situations aren\'t they?

Any code examples to

4条回答
  •  遇见更好的自我
    2021-02-20 17:22

    When do you want them to fire?

    CREATE TRIGGER AFTER ACTION
    

    That runs after the action (insert update delete) being committed. INSTEAD OF fires the trigger in place of the action.

    One of the biggest gotchas with triggers is that they fire whenever an action is performed, even if no rows are affected. This is not a bug, and it's something that can burn you pretty quickly if you aren't careful.

    Also, with triggers, you'll be using the inserted and deleted tables. Updated rows are listed in both. This throws a lot of folks off, because they aren't used to thinking about an update as a delete then insert.

    The MSDN documentation actually has a pretty in-depth discussion about when triggers fire and what effect they have here.

提交回复
热议问题