Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Sql Triggers synchronous or asynchronous?

I have a table that has an insert trigger on it. If I insert in 6000 records into this table in one insert statement from a stored procedure, will the stored procedure return before the insert trigger completes?

Just to make sure that I'm thinking correctly, the trigger should only be called (i know 'called' isn't the right word) once because there was only 1 insert statement, right?

My main question is: will the sproc finish even if the trigger hasn't completed?

like image 844
Miles Avatar asked Oct 16 '08 20:10

Miles


People also ask

Are triggers synchronous?

Triggers are run synchronously by default. Asynchronous triggers run in the background, independent of other operations that follow. They are typically run after an event completes.

Are mysql triggers asynchronous?

Yes, triggers are synchronous.

Is SQL synchronous?

The native SQL Server AlwaysOn mirroring replicates synchronously.

What are 3 types of SQL triggers?

SQL Server has three types of triggers: DML (Data Manipulation Language) Triggers. DDL (Data Definition Language) Triggers. Logon Triggers.


1 Answers

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

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

like image 82
tom.dietrich Avatar answered Sep 22 '22 15:09

tom.dietrich