When do triggers fire and when don't they

后端 未结 4 2046
感动是毒
感动是毒 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:23

    The following statement only fires the update trigger once.

    Any action type statement only fires the trigger once no matter how many rows are affected, triggers must be written to handle multiple row inserts/updates/deletes.

    If your trigger depends on only one row at a time being in the inserted or deleted pseudotables, it will fail. And worse it will not fail with an error, it will simply not affect all the rows you want affected by whatever the trigger does. Do not fix this through a loop or a cursor in a trigger, change to set-based logic. A cursor in a trigger can bring your entire app to a screeching halt while a transaction of 500,000 records processes and locks up the table for hours.

    Bulk inserts by pass triggers unless you specify to use them. Be aware of this because if you let them by pass the trigger you will need code to make sure whatever happens in the trigger also happens after the bulk insert. Or you need to call the bulk inserts with the FIRE_TRIGGERS option.

提交回复
热议问题