Database transactions and Database Transaction Processing

Source: Internet
Author: User

Database transactions and Database Transaction Processing
Concept of database transactions
An operation between two consecutive successful COMMIT or ROLLBACK is called a transaction. In a transaction, data modifications are committed or withdrawn together. If a fault or system error occurs, the entire transaction is automatically canceled.
For example, the procedure of transferring money from a bank can be divided into the following two steps:
(1) draw money from the first account.

(2) deposit the money into the second account.

In this process, two links are associated. The first account must be properly deposited into the second account. If the second step is not completed, the entire process should be canceled. Otherwise, the amount will be lost.
The entire transaction process can be viewed as a transaction. If the transaction succeeds, all transactions are successful, and if the transaction fails, all transactions need to be undone. This prevents data inconsistency when a problem occurs in the intermediate link of the operation.

Application of Database transactions
There are two types of Database Transaction Processing: implicit and explicit. Explicit transaction operations are implemented through commands. Implicit transactions are automatically committed or uncommitted by the system without user intervention.
Implicit commit includes automatic commit of transactions when the user exits SQL * Plus normally or executes commands such as CREATE, DROP, GRANT, and REVOKE.

Set the environment variable AUTOCOMMIT to ON (the default status is OFF)
Set autocommit on/OFF
Implicit rollback includes automatic transaction rollback when an SQL * Plus exception is terminated or a system failure occurs.


How to start a new transaction?
Generally, starting a session (that is, connecting to the database), executing the first SQL statement will start a new transaction, or executing a COMMIT or ROLLBACK to cancel the transaction, it also marks the start of a new transaction. In addition, executing DDL (such as CREATE) or DCL commands will automatically commit the previous transaction and start a new transaction.

Related Article

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.