[ACCEPTED]-Are Sql Triggers synchronous or asynchronous?-timing

Accepted answer
Score: 27

Your insert trigger will run once for the 9 entire insert statement. This is why it 8 is important to use the inserted temporary table 7 to see what has actually been inserted, and 6 not just select the most recent single record, or 5 something like that.

I just tested an insert 4 and update trigger and indeed, they are 3 considered part of the insert by sql server. the 2 process will not finish until the trigger 1 finishes.

Score: 7

Triggers are part of the transaction that 13 called them.

One important thing about triggers 12 that you must be aware of is that the trigger 11 fires once for each transaction (at least 10 in SQL server, you should check other dbs, but 9 even if it will process row by row, that 8 is usually a poor idea), so if you insert 7 6000 records the trigger fires once not 6 6000 times. Many people are not aware of 5 this and write triggers as if they will 4 process multiple record inserts one record 3 at a time. This is not true and your trigger 2 must account for handing the multiple record 1 insert.

Score: 1

The trigger call is not asynchronous. Each 6 call to your insert procedure will result 5 in the trigger being fired, and the procedure 4 will not return until the trigger finishes.

Take 3 a look at the query plan to see how it works. You'll 2 see that the statements in the trigger will 1 be called for each call to the procedure.

Score: 1

The thing is, every time the TRIGGER criteria 3 is met, the TRIGGER fires. It fires once 2 in batch processing or Transaction. See 1 my lesson 101 on TRIGGER

More Related questions