Message 3902, Level 16, State 1, row 3rd COMMIT TRANSACTION request does not have a corresponding BEGIN TRANSACTION.

Source: Internet
Author: User

Write a simple INSERT statement in SQL Server and submit:

INSERT into EMP (empno,ename) VALUES (2, ' Dan ');

Commit

Result Error:

Message 3902, Level 16, State 1, row 3rd COMMIT TRANSACTION request does not have a corresponding BEGIN TRANSACTION.

The reason for the error: It is true to write this in Oracle, but this SQL Server environment. Grammar needs to change.

Solution:

It should be written like this:

BEGIN TRANSACTION;
INSERT into EMP (empno,ename) VALUES (2, ' Dan ');

Commit TRANSACTION;

At the same time, I found that if I did not commit in SQL Server, I would open a session and still see the changed data. But in Oracle, this is absolutely invisible, unless the data is submitted. DML operations in SQL Server are submitted automatically. As a result, transactions are sometimes used.

Database transaction (DB Transaction) is a series of actions performed as a single logical unit of work. Transaction processing ensures that data-oriented resources are not permanently updated unless all operations within the transactional unit are completed successfully. By combining a set of related actions into a unit that is either fully successful or all failed, you can simplify error recovery and make your application more reliable. To be a transaction, a logical unit of work must satisfy the so-called acid (atomicity, consistency, isolation, and durability) attribute.

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.