事物(transaction):指一组SQL语句
回退(rollback):指撤销指定SQL语句的过程
提交(commit):指将未存储的SQL语句结果写入数据库表
保留点(savepoint):指事务处理中设置的临时占位符(place-holder),你可以对它发布回退
事物处理用来管理INSERT、UPDATE和DELETE语句。不能回退CREATE或DROP操作。
使用ROLLBACK
SELECT * FROM ordertotals;
START TRANSACTION;
DELETE FROM ordertotals;
SELECT * FROM ordertotals;
ROLLBACK;
select * from ORDERTOTALS;
使用COMMIT
START TRANSACTION;
DELETE FROM orderitems WHERE order_num = 2010;
DELETE FROM orders WHERE order_num = 20010;
COMMIT;
使用保留点
SAVEPOINT delete1;
ROLLBACK TO delete1;
更改默认的提交行为
SET autocommit = 0; -- 指示MySQL不自动提交更改