事务提交和回滚

操作方法

begin; -开始事物

commit; - 提交事物  Python 默认是取消自动提交的

rollback; - 回撤操作, 只要操作没有执行 commit 就可以进行回滚操作, 撤回


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);

  -- 开启一个事物   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 不会删除表

  rollback;

---------------------


原文:https://blog.csdn.net/zhang_ming_lu/article/details/80835766

你可能感兴趣的:(事务提交和回滚)