CREATE DATABASE `shop` CHARACTER SET utf8 COLLATE utf8_general_ci标签:转账,account,SET,name,--,money,sql,NULL,模拟 From: https://www.cnblogs.com/huangjiangfei/p/18057219
CREATE TABLE `account`(
`id` INT(3) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(10) NOT NULL,
`money` DECIMAL(9,2) NOT NULL,
PRIMARY KEY(id)
)ENGINE=INNODB DEFAULT CHARSET=utf8
INSERT INTO account(`name`,`money`) VALUES('A',2000.00),('B',10000.00)
-- 模拟事物转账
SET autocommit=0;
START TRANSACTION; -- 开启一个事物
UPDATE account SET money=money-500 WHERE `name`='A';
UPDATE account SET money=money+500 WHERE `name`='B';
COMMIT;--提交
ROLLBACK;--回滚
SET autocommit = 1;-- 恢复默认值