INF: Rollback from Within Triggers

Last reviewed: April 25, 1997
Article ID: Q45581

The information in this article applies to:

  - Microsoft SQL Server version 4.2 for OS/2

SUMMARY

ROLLBACK TRANSACTION behaves differently when used within a trigger than when not within a trigger.

MORE INFORMATION

When not within a trigger, ROLLBACK TRANSACTION must have a matching BEGIN or SAVE point. When not within a trigger, ROLLBACK TRANSACTION backs out uncommitted updates, but does not alter the flow of control of the Transact-SQL batch or stored procedure. To stop processing a stored procedure, an explicit RETURN must be executed in addition to the ROLLBACK.

When within a trigger, it is not necessary to have a matching BEGIN TRANSACTION statement because each SQL statement that is not within an explicit transaction is effectively a one-statement transaction. Nothing at the SQL batch or stored procedure can get "inside" such a one-statement transaction; however, the Transact-SQL statement within a trigger is effectively "inside" the one-statement transaction, and therefore it does make sense to allow an unbalanced rollback to the beginning of the one-statement transaction.

Triggers can also execute as part of a larger transaction. Whether or not they do so, another difference is that a ROLLBACK within a trigger causes the entire SQL batch to be terminated. There is no need for an explicit RETURN to alter the flow of control, nor is there any way to prevent the termination of the batch. The trigger itself does continue to execute after the ROLLBACK is issued; however, when it exits, the rest of the batch is aborted.


Additional query words: Triggers rules stored procedures
Keywords : kbprg SSrvServer
Version : 4.2
Platform : OS/2


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 25, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.