操作方法
begin; -開始事物
commit; - 提交事物? Python 默認(rèn)是取消自動(dòng)提交的
rollback; - 回撤操作, 只要操作沒有執(zhí)行 commit 就可以進(jìn)行回滾操作, 撤回
create table tb_account
? (
? accid char(4) not null,
? uname varchar(20) not null,
? balance float default 0
? )
? insert into tb_account values
? ('1111', '張明祿', 1200.99),
? ('2222', '王大錘', 500);
? -- 開啟一個(gè)事物 ? start transaction
? begin;
? update tb_account set balance=balance-1000
? where accid='1111';
? update tb_account set balance=balance+1000
? where accid='2222';
? commit; ? -- 提交 才能改變
? rollback; ?-- 撤銷
? ?
? begin;
? delete from? tb_account; ?-- 沒有commmit 不會(huì)刪除表
? rollback;
---------------------
原文:https://blog.csdn.net/zhang_ming_lu/article/details/80835766