MySQL Management Transactions
This paper describes how to use COMMIT
and ROLLBACK
statement transaction management
Transaction Processing
What transactions are?
- Maintain database integrity
- Batch SQL statement, either all executed or not executed
Transaction What is the role?
Transactions can use to ensure that a set of operations will not stop halfway, or perform them as a whole, or simply do not perform.
If an error occurs, then fall back to a known safe state
Several important terms
the term | |
---|---|
Transaction (transaction) | It refers to a group of sql statement |
Rollback (rollback) | It refers to the process of revocation of sql statement |
Submit (commit) | It refers to data not stored in the result table write sql |
Retention point (save point) | Transaction set during a temporary placeholder can publish their fallback |
Control Transactions
- Use rollback roll back a transaction
# 事务开始
START TRANSACTION;
DELETE FROM ordertotals;
SELECT * FROM ordertotals;
ROLLBACK;
SELECT * FROM ordertotals;
rollback
Can only be used in a transaction,start transaction
- Use commit to commit the transaction
# 26.2.2 使用COMMIT
START TRANSACTION;
DELETE FROM orderitems WHERE order_num=20010;
DELETE FROM orders WHERE order_num=20010;
COMMIT ;
- Use a reserved spot savepoint
SAVEPOINT delete1;
-- 回退
ROLLBACK delete1;
- Change the default submit behavior
Mysql default behavior is to automatically submit the changes, the changes take effect immediately, but you can not automatically submit the changes set
SET autocommit=0;
Up autocommit
to 1, before submitting changes