SQL transaction Processing

Source: Internet
Author: User

Database updates are usually caused by events that occur in the objective world. In order to ensure the consistency of the database content, a set of operations of the database should be carried out as a whole, either complete successfully or all fail out. If there is some completion in a set of operations due to a failure or other reason, and some unfinished, the data in the database is bound to be inconsistent, causing the integrity of the database to be compromised. Therefore, the update action sequence must appear as a whole when the DBMS executes, that is, "either all or none." SQL provides a mechanism for transaction processing to help the DBMS achieve these functions.

Transaction processing (TRANSACTION) is a logical processing unit formed by the combination of one or more SQL statement sequences. Each statement in a transaction is part of the entire task, and all the statements are organized together to accomplish a particular task. When a DBMS processes a statement in a transaction, it does so according to the following conventions, and that is, "all statements in a transaction are treated as an atomic unit of work, and all statements can be executed successfully or without any statement being executed." The DBMS is responsible for such a convention, even if the application exits unexpectedly in a transaction, or in various unexpected situations, such as a hardware failure. In any unexpected case, the DBMS is responsible for ensuring that the database contents never appear "executed in part of the transaction" after the system is restored to normal.

The SQL language provides two important statements for transactional processing, which are commit and rollback statements. They are used in the following formats:

COMMIT WORK

ROLLBACK WORK

A commit statement is used to tell Dmbs that the statement in the transaction was successfully executed. The database content will be complete when the execution is completed successfully. The rollback statement is used to tell the DBMS that the statement in the transaction cannot be executed successfully. At this point, the DBMS will revert to the changes made to the database during this transaction to revert to the state before the transaction process.

References: SQL language tutorials SQL language basics

Back to the database basics ABC Directory

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.