How a trigger fires when multiple rows are inserted into a single transaction

I created a FOR INSERT trigger that will fire after insertion. Below are the various scenarios for which I would like to know how the trigger works.

The trigger is in the employee table. I start one transaction when I insert 4 rows. My doubt is how the trigger works.

  • Will it start immediately after inserting each row?
  • Whether it will be launched after completion of all lines in this transaction.

We can access the special inserted and deleted tables from the trigger.

  • How many rows will be present in these tables each time? Only one entry? Or a few entries?

Thanks in advance.

+7
source share
1 answer

The trigger fires after each INSERT .

If you have 4 INSERT statements, each of 1 line, the trigger will be run 4 times with 1 entry in the special inserted table after each insertion.

If you have 1 INSERT of 4 lines, the trigger will be run only once with 4 entries in the special inserted table after insertion.

If these are transactional inserts, the actions you perform in the trigger will also be transactional. This is very important if the trigger has an internal transaction.

+11
source

All Articles