I. Transaction Concept
Concept: transactions in databases are logical units of work. A transaction is composed of one or more SQL statements that complete a group of related behaviors, the transaction mechanism is used to ensure that the operations performed by these SQL statements are either completely successful, and the whole unit of work is completed or not executed at all.
Ii. Features of things
A) main features: ensure the integrity of the database.
B) ACID properties of transactions
I. Atomicity)
The atomicity of a transaction indicates that all operations contained in a transaction are either fully or not performed. That is to say, all activities are either fully reflected or not reflected in the database to ensure Database Consistency.
Ii. Consistency)
Transaction consistency means that data in the database must meet the business rule constraints before and after transaction operations and after transaction processing.
Iii. Isolation)
Isolation refers to the ability of the database to allow multiple concurrent transactions to read or modify the data at the same time. isolation can prevent concurrent execution of multiple transactions, data inconsistency is caused by cross-execution of their operation commands.
Iv. durability)
Transaction Persistence means that after the transaction processing is completed, its modifications to the data should be permanent. Even if the system encounters a fault, it will not be lost, which is determined by the importance of data.
Iii. Data exceptions
A) the isolation of a transaction defines the degree of isolation between a transaction and other transactions. to better understand the isolation layer, we first discuss the possible access to the same database by concurrent transactions. in general, concurrent transactions occur.
I. Wrong read | dirty read
Wrong read | dirty read: when a transaction modifies the data, the other transaction reads the data, but the first transaction cancels the data modification for some reason and returns the data to the original state, this is because the data read by the second transaction is inconsistent with the data in the database. this is called an error.
Ii. Non-repeated read | non-repeated read
Non-repeated read: after a transaction reads data from the database, the other transaction updates the data. When the first transaction reads the data again, you will find that the data has changed, which is non-repeated read. The result of Non-repeated reads is that the data read twice before and after a transaction is different.
Iii. False read | phantom read
False read: if a transaction reads data based on a certain condition, the other transaction updates the data in the same table. When the first transaction reads data again, different rows are returned based on the search criteria. This is a false read.
B) The exceptions encountered in the transaction are related to the transaction isolation settings. The more the transaction isolation settings, the fewer exceptions will occur, but the lower the concurrency effect, the less the isolation settings of transactions, the more exceptions occur, and the higher the concurrency effect.