There is only one transaction name in the same connection

Source: Internet
Author: User

See http://www.cnblogs.com/hongten/archive/2011/06/18/2084036.html

Using one transaction name in a series of nested transactions to name multiple transactions has no effect on this transaction. The system registers only the first (most external) transaction name. Rolling back to any other name (except for storing names effectively) produces an error.

In fact, no statement executed before rollback is rolled back when an error occurs. This statement will be rolled back only when the outer transaction is rolled back.

For example, an error is returned when an internal transaction is rolled back to SQL Server.

Begin Tran T1
Insert into demo2 (name, age) values ('Lis ', 1)
--- Second Trans
Begin transaction T2

Insert into demo values ('bb ',' B terminologies ')
RollbackTransaction T2
---- In the first trans.
Insert into demo2 (name, age) values ('Lis ', 2)
Commit transaction T1

An error is reported during transaction T2 rollback:

-- Server: MSG 6401, level 16, state 1, line 6
-- Cannot roll back T2. no transaction or savepoint of that name was found.

For example, SQL server does not report an error when internal transactions are committed.

Begin Tran T1
Insert into demo2 (name, age) values ('Lis ', 1)
Begin transaction t2
Insert into demo values ('bb ',' B terminologies ')
CommitTransaction t2 -- correct
---- In the first trans.
Insert into demo2 (name, age) values ('Lis ', 2)
Commit transaction t1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.