Thursday, August 11, 2011

AFTER Triggers on SQL Server - Are they Row Level or Statement Level

In SQL Server, you cannot specify explicitly whether the triggers should fire at ROW level (for each row) or STATEMENT level (for a statement, irrespective of rows).

The default and the only trigger execution in SQL Server is at STATEMENT LEVEL.

That means, each of the corresponding trigger fires once for either INSERT, UPDATE or DELETE.

So if you have an insert statement that will affect 5000 rows, then the trigger will fire only once as it has only a single statement.
If you have 5000 separate insert statements that insert one row of data at a time, then the trigger will fire 5000 times (i.e, once for each insert statement).

Do you see the similarity above? It always talks about the statement, irrespective of the number of rows it acts on.



Confidentiality Note: The information contained in this e-mail and documents attached are for the exclusive use of the addressee and contain confidential and privileged information that may not be disclosed. If the recipient of this e-mail is not the addressee, or intended addressee such recipient is strictly prohibited from reading, photocopying, distributing or otherwise using this email or its contents in any way.

No comments:

Post a Comment