Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update trigger - why it works?
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01291246
Message ID:
01291502
Views:
7
Hi Borislav,

The first line in the Using Nested Triggers answered my question
An AFTER trigger does not call itself recursively unless the RECURSIVE_TRIGGERS database option is set.

So, since I didn't change this setting and use its default value, it worked.

However, I guess, this is not a save approach.

Is there any other way to change a value of the field of a table when another field is changed? Say, in my case I want to always set Drop_Date to current date if I set status to 'D'.

This was just an exercise, but I'd like to understand the concept.

Thanks again for your help.



>Check Recursive Triggers under CREATE TRIGGER topic in BOL:
>
>Recursive Triggers
>SQL Server also allows for recursive invocation of triggers when the RECURSIVE_TRIGGERS setting is enabled using ALTER DATABASE.
>Recursive triggers enable the following types of recursion to occur:
>Indirect recursion
>With indirect recursion, an application updates table T1. This fires trigger TR1, updating table T2. In this scenario, trigger T2 then fires and updates table T1.
>
>Direct recursion
>With direct recursion, the application updates table T1. This fires trigger TR1, updating table T1. Because table T1 was updated, trigger TR1 fires again, and so on.
>
>The following example uses both indirect and direct trigger recursion Assume that two update triggers, TR1 and TR2, are defined on table T1. Trigger TR1 updates table T1 recursively. An UPDATE statement executes each TR1 and TR2 one time. Additionally, the execution of TR1 triggers the execution of TR1 (recursively) and TR2. The inserted and deleted tables for a specific trigger contain rows that correspond only to the UPDATE statement that invoked the trigger.
>
>Note:
>The previous behavior occurs only if the RECURSIVE_TRIGGERS setting is enabled by using ALTER DATABASE. There is no defined order in which multiple triggers defined for a specific event are executed. Each trigger should be self-contained.
>
>
>
>Disabling the RECURSIVE_TRIGGERS setting only prevents direct recursions. To disable indirect recursion also, set the nested triggers server option to 0 by using sp_configure.
>
>If any one of the triggers performs a ROLLBACK TRANSACTION, regardless of the nesting level, no more triggers are executed.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform