TRANSACTION (transaction) is a logical unit in the execution process of database management system, which is composed of a limited sequence of database operations.
Database transactions usually contain a sequence of read / write operations to the database. It includes the following two purposes:
It provides a method for the database operation sequence to recover from failure to the normal state, and provides a way for the database to maintain consistency even in the abnormal state.
When multiple applications are accessing the database concurrently, you can provide an isolation method between these applications to prevent each other’s operations from interfering with each other.
When a transaction is committed to the database management system (DBMS), DBMS needs to ensure that all operations in the transaction are completed successfully and that the results are permanently saved in the database. If some operations in the transaction are not completed successfully, all operations in the transaction need to be rolled back to the state before the transaction is executed. At the same time, the transaction has no effect on the execution of the database or other transactions, and all transactions seem to be running independently. Transactions have the following four standard attributes, usually abbreviated to ACID according to their initials: Atomicity: transactions are executed as a whole, and either all or none of the operations on the database are performed. Consistency: transactions should ensure that the state of the database transitions from one consistent state to another. The meaning of consistent state is that the data in the database should meet the integrity constraints. Isolation: when multiple transactions are executed concurrently, the execution of one transaction should not affect the execution of other transactions. Durability: changes made to the database by committed transactions should be permanently saved in the database. Someone wants to use electronic money to buy something worth 100 yuan in a store, which includes at least two operations: The person’s account was reduced by 100 yuan. The store account will be increased by 100 yuan. The database management system that supports transactions is to ensure that the above two operations (the whole “transaction”) can be completed or cancelled together, otherwise 100 yuan will disappear or appear in vain. Use the following command to control the transaction: 5.38.1. Properties of the transaction ¶
5.38.2. Examples ¶
5.38.3. Transaction control ¶