What is a database transaction?
A transaction is a program execution unit consisting of a series of operation sequences. These operations are either done or not done, and are an inseparable unit of work.
Four basic properties of database transactions (ACID)
1. Atomicity)
The atomicity of a transaction indicates that all operations contained in a transaction are either performed in full or not (all or none ).
2. Consistency)
Before a transaction starts, the database is in the consistent state. After the transaction ends, the database must also be in the consistent state.
For bank transfers, consistency requires that the execution of transactions should not change the sum of the two accounts A and B. Without such consistency requirements, money may be lost or missing during the transfer process. Transactions should switch the database from one consistent state to another consistent state.
3. Isolation)
Transaction isolation requires the system to ensure that the transaction is not affected by other concurrent transactions, that is, to achieve the effect: For any pair of transactions T1 and T2, in transaction T1, t2 is executed either before T1 or after T1 is completed. In this way, every transaction does not feel that other transactions are being executed concurrently in the system.
4. Durability)
Once a transaction is successfully completed, its changes to the database must be permanent and will not be lost even if the system encounters a fault. The importance of data determines the importance of transaction persistence.