BEGIN TRANSACTION statement
408
Caution
When calling a stored procedure, you should ensure that it operates
correctly under the required transaction mode.
$ For more information, see "CHAINED option" on page 175.
The current nesting level is held in the global variable @@trancount. The
@@trancount variable has a value of zero before the first BEGIN
TRANSACTION statement is executed, and only a COMMIT executed
when @@trancount is equal to one makes changes to the database
permanent.
A ROLLBACK statement without a transaction or savepoint name always
rolls back statements to the outermost BEGIN TRANSACTION (explicit or
implicit) statement, and cancels the entire transaction.
♦
SQL/92 Vendor extension
♦
Sybase Supported by Adaptive Server Enterprise.
♦ The following batch reports successive values of
@@trancount
as 0, 1,
2, 1, and 0. The values are printed on the server window.
PRINT @@trancount
BEGIN TRANSACTION
PRINT @@trancount
BEGIN TRANSACTION
PRINT @@trancount
COMMIT
PRINT @@trancount
COMMIT
PRINT @@trancount
You should not rely on the value of@@trancount for more than keeping
track of the number of explicit BEGIN TRANSACTION statements that
have been issued.
When Adaptive Server Enterprise starts a transaction implicitly, the
@@trancount variable is set to 1. Adaptive Server Anywhere does not set the
@@trancount value to 1 when a transaction is started implicitly.
Consequently, the Adaptive Server Anywhere @@trancount variable has a
value of zero before any BEGIN TRANSACTION statement (even though
there is a current transaction), while in Adaptive Server Enterprise (in
chained mode) it has a value of 1.
Standards and
compatibility
Example