11. Trigger Configuration Properties
The trigger configuration properties, as shown in Table 11, control trigger behavior in SQL Server.
Table 11 Trigger Configuration Properties
Trigger behavior can be set at both the server and database levels.
Nested Triggers
A trigger is a small stored procedure executed on an insert, update, or delete
operation on a table. Triggers are nested when a trigger performs an
action that initiates another trigger, which can initiate another
trigger, and so on. Triggers can be nested up to 32 levels. You can use
the nested triggers server configuration option to control whether AFTER trigger can be nested triggers.
In Management Studio, you can set the nested trigger
option by selecting True (default) or False in the Allow Triggers to
Fire Others option on the Server Properties Advanced tab .
To turn nested triggers OFF in code, do the following:
EXEC sp_configure ‘nested triggers', 0;
RECONFIGURE;
Note
INSTEAD OF triggers can be nested regardless of the setting of this option.
Recursive Triggers
If the code in the trigger inserts,
updates, or deletes the same table again, then the trigger causes
itself to be executed again. Recursion can also occur if the code in
the trigger fires and performs an action that causes a trigger on
another table to fire. This second trigger performs an action that
causes an update to occur on the original table, which causes the
original trigger to fire again. Recursive behavior is enabled or
disabled by the recursive trigger database option. By default, the RECURSIVE_TRIGGERS option is set to off.
In Management Studio, the recursive triggers
option can be enabled by selecting True in the Recursive Triggers
Enabled option in the Database Properties Options tab (.
To set the recursive triggers option on in the AdventureWorks2012 sample database in T-SQL code, do the following:
ALTER DATABASE AdventureWorks2012 SET RECURSIVE_TRIGGERS ON;