INF: Behavior of Cascading Triggers with Recursive CallsLast reviewed: April 3, 1997Article ID: Q89655 |
The information in this article applies to:
- Microsoft SQL Server version 4.2 for OS/2
SUMMARYIn the Microsoft SQL Server for OS/2 version 4.2 "Language Reference" manual under CREATE TRIGGER, two statements refer to recursive behavior of cascading triggers. These statements are not complete in their description of cascading triggers with recursive calls and can be misinterpreted. The purpose of this article defines expected behavior of cascading triggers and the possible recursive elements.
MORE INFORMATIONThere are two statements that appear on page 90 of the "Language Reference" manual for SQL Server that describe behavior of cascading triggers and possible recursion. The two statements are as follows:
If it is desired that a trigger cannot fire any other trigger on the same table, the triggers should be combined into one single trigger, or the database option for cascading triggers should be turned off. Statement number two says that a trigger activates only once per single data modification statement. This is correct, but it is important to understand that any INSERT, UPDATE, or DELETE statement fired by a trigger is its own single data modification statement. With this in mind, it is possible to establish a recursive loop between two or more triggers where the triggers can be on one or more tables. If an uninterrupted recursive loop is encountered, all statements will be rolled back after the maximum depth of 16 cascading triggers is reached. To clarify how a recursive trigger can occur, use the following example:
With understanding of the above information and careful design of the database, cascading triggers can be a valuable piece of the database design.
|
Additional query words: 4.20 Transact-SQL Trigger
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |