## Database transactions
### meaning
Through a set of logical operation units ( a set DML——sql sentence ), Switching data from one state to another
### characteristic
(ACID)
Atomicity : Either it's all done , Either roll back
uniformity : Ensure the data state is consistent before and after operation
Isolation : When multiple transactions operate on the same data in the same database at the same time , The execution of one transaction is not interfered by another
persistence : Once a transaction is committed , The data is persisted locally , Unless it is modified by another transaction
Related steps :
1, Open transaction
2, A set of logical operating units that write transactions ( Multiple sql sentence )
3, Commit or roll back a transaction
### Classification of transactions :
Implicit transaction , There are no obvious signs of opening and closing transactions
such as
insert,update,delete The statement itself is a transaction
Explicit transaction , There are obvious marks for opening and ending transactions
1, Open transaction
Cancel auto commit transactions
2, A set of logical operating units that write transactions ( Multiple sql sentence )
insert
update
delete
3, Commit or roll back a transaction
### Keywords used
set autocommit=0;
start transaction;
commit;
rollback;
savepoint breakpoint
commit to breakpoint
rollback to breakpoint
### Isolation level of the transaction :
How does transaction concurrency occur ?
When multiple transactions operate on the same data in the same database at the same time
What are the concurrency problems of transactions ?
Dirty reading : One transaction read uncommitted data from another transaction
Non repeatable : In the same transaction , Inconsistent data read multiple times
Illusory reading : When a transaction reads data , Another transaction is updated , This causes the first transaction to read data that is not updated
How to avoid concurrency of transactions ?
By setting the isolation level of the transaction
1,READ UNCOMMITTED
2,READ COMMITTED It can avoid dirty reading
3,REPEATABLE READ It can avoid dirty reading , Non repeatable reading and some unreal reading
4,SERIALIZABLE It can avoid dirty reading , Nonrepeatable reading and unreal reading
Set isolation level :
set session|global transaction isolation level Isolation level name ;
View isolation level :
select @@tx_isolation;
Technology