INF: Example of Using Nested Triggers

Last reviewed: April 28, 1997
Article ID: Q79886

The information in this article applies to:

  - Microsoft SQL Server version 4.2 for OS/2

SUMMARY

The following script shows the use of nested triggers. The output shows how the inner trigger is completed before the calling trigger is completed.

MORE INFORMATION

Script

   use pubs
   go

   create table t1(a int)
   go
   create table t2(a int)
   go
   create trigger t1it on t1 for insert as
       print "begin t1it"
       insert t2 values(1)

   /* (select count(*) from inserted) */
       print "end   t1it"
   go

   create trigger t2it on t2 for insert as
       print "begin t2it"
       print "end   t2it"
   go

   insert t1 values (1)
   go

Output

begin t1it begin t2it end t2it end t1it (1 row affected)

NOTE: If triggers are nested such that a circular link is formed, an error message will be returned indicating that the maximum nesting level has been exceeded.


Additional query words:
Keywords : kbother SSrvServer
Version : 4.2
Platform : OS/2
Issue type : kbtshoot
Resolution Type : kbcode


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.