Four isolation levels of transactions and transaction characteristics

What is a transaction?

Generally it refers to things to do or have done. The term is meant computer may access and update the database in a variety of program execution unit data items (unit).

A transaction can be a SQL statement, a set of SQL statements or the entire program.

So the database and the transaction is associated with four properties and transaction isolation level of the transaction is about the database.

Understand the four characteristics of the transaction (ACID)

1, atomicity (Atomicity)

If you open a transaction, then the transaction contains sql statement either all executed or not executed all, as I said before a transaction can be a SQL statement, a set of SQL statements or the entire program.

Example: Transfer Services: A turn to B 100 yuan, 100 yuan to lose either A, B get 100 yuan, the transfer is successful, or 100 yuan is still A, B of A did not receive 100 yuan, transfer failure

2. Consistency (Consistency)

Services for additions and deletions to modify the operation of the database to ensure data consistency,

For example: A transfer operations account 1000 yuan, B account money, mutual transfers between AB, to ensure that the total number is 1,000 yuan, more or less impossible, and this is consistent; it means data must be real there are sources, there is going, do not appear out of thin air or disappear.

3, isolation (Isolation)

Transaction isolation also called independence, refers to two or more staggered implementation of the state of affairs does not occur. As this may result in inconsistent data.

 

4, persistent (Durability)

After the transaction is successful, changes to the database are permanent, will not be rolled back for no reason.

 

Transaction isolation level of understanding

Read uncommitted (read uncommitted) happened dirty read

A transaction can read data from another uncommitted transactions 

A transaction made modifications to the database but does not submit (commit), this time we can read (queried) to modify the data, but if the transaction rollback (rollback), we read before the data is dirty data is invalid data. Overall this isolation level will happen dirty read situations

Read Committed (Read Committed) resolved dirty reads, non-repeatable read occurs

A transaction to wait until after the transaction commits another read data.

Example: A bank card is $ 100, then his wife to turn away 100 yuan, when the A's to spend 100 yuan Cary found no

Within the scope of a transaction of the same query twice but get different data, which is what has happened non-repeatable read

Repeatable Read (Repeatable Read) solves dirty reads and non-repeatable read, phantom read occurs

When a transaction is not allowed to open to do other transactions that modify operations.

A modification to the database transaction open, while B transaction query the database, B end of the first query submitted a modified A, B again when the query data found that the two are not the same, this is the phantom reads .

The Serializable (serialization) solved dirty reads, non-repeatable read and phantom read

The highest transaction isolation level, the cost of the highest cost, low performance, rarely used, at this level, the branch order to avoid the above situation arising.

 

Guess you like

Origin www.cnblogs.com/from-java-to-world/p/11304690.html