@author: Tobin
@date: 2019/11/7 17:27:01
事务处理用来维护数据库的完整性,保证成批的MySQL操作要么不执行,要么都执行。
InnoDB支持事务处理。
ROOLBACK:回退。不能回退CREATE和DROP
SELECT * FROM ordertotals;
START TRANSACTION;
DELETE FROM ordertotals;
SELECT * FROM ordertotals;
ROOLBACK;
SELECT * FROM ordertotals;
COMMIT:类比写回,如果语句执行有部分不成功,就不会执行
START TRANSACTION;
DELETE FROM order_items WHERE order_num = 20010;
DELETE FROM orders WHERE order_num = 20010;
COMMIT;
SAVEPOINT:保留点,部分回退
SAVEPOINT delete1;
ROOLBACK TO delete1;
默认的MySQL语句是自动提交所有更改的。
不默认提交使用下面的语句。
SET autocommit = 0;