假如我们有一个表,为account,其内容为:
ID | NAME | BALANCE |
1 | zhangsan | 1000 |
2 | lisi | 1000 |
比如支付宝转账!张三转1000块到李四的账户,这其实需要两条SQL语句:
START TRANSACTION; UPDATE account SET balance=balance-1000 WHERE id=1; UPDATE account SET balance=balance+1000 WHERE id=2; ROLLBACK;
START TRANSACTION; UPDATE account SET balance=balance-1000 WHERE id=1; UPDATE account SET balance=balance+1000 WHERE id=2; COMMIT;
原文地址:http://blog.csdn.net/qq_16216221/article/details/46514221