Sql statement or a group consisting of one execution unit, the execution unit performs either all, or all not be executed. Such as: transfer.
Atomicity (Atomicity): a transaction are either executed or rolled back (not subdivided)
Consistent operation before and after the operating state ensure data: Consistency (Consistency)
Isolation (Isolation): When multiple transactions simultaneously operate on the same data in the same database, a transaction is not executed a transaction otherwise interfere
Persistent (Durability): Once a transaction is committed, the data is persisted to the local (data will be permanent changes to the database), unless other transactions modify
Step transaction
1、开启事务
2、编写事务的一组逻辑操作单元(多条sql语句)
3、提交事务或回滚事务
Step # demonstrate the use of a transaction to transfer :( for example) # open transaction the SET autocommit = 0 ; Start Transaction; # to prepare a set of transaction statements Update the Account the SET Balance = 500 the WHERE usename = ' Wuji ' ; Update the Account the SET Balance = 1500 the WHERE usename = ' Guo Xiang ' ; # end transaction commit;
Affairs Category:
Implicit transaction, there is no obvious sign of opening and end of the transaction
insert, update, delete statement itself is a transaction
Flag explicit transaction, with a clear opening and closing of the transaction
Prerequisite: Cancel automatic submission function SET the autocommit = 0 ; . 1 , open transaction start transaction; may be omitted 2 , prepared by a set of logical operations of the transaction units (multiple sql statement) INSERT Update Delete provided rollback point: savapoint rollback named; 3 , commit the transaction or roll back the transaction submitted to: commit; rollback: rollback; rollback to the designated place: rollback to roll back the roll call;
Use the keyword
SET the autocommit = 0 ; Start Transaction; the commit; ROLLBACK; that the savepoint breakpoint commit to break rollback to break
reference:
https://www.jianshu.com/p/6738c4b11da8