管理事务处理
事务处理(transanction processing)可以用来维护数据库的完整性,它保证成批的MySQL操作要么完全执行,要么完全不执行。
ROLLBACK撤销
1 2 3 4 5 6
| select * from ordertotals; start transaction delete from ordertotals; select * from ordertotals; rollback; select * from ordertotals;
|
COMMIT提交
1 2 3 4
| start transaction; delete from orderitems where order_num = 20010; delete from orders where order_num = 20010; commit;
|
- 只有两个DELETE都操作成功,该删除命令才会执行,否则都不执行。
SAVEPOINT保留点
1 2 3 4
| savepoint delete1;
rollback to dalete1;
|
更改默认提交行为
1 2 3 4
| SET autocommit = 0;
SET autocommit = 1;
|
小结
就先这样吧,以后刷题的时候再深入学习。