香港vps的mysql使用事务修改表的示例:
1.新建一个表,代码:
create table account(
id char(10) primary key,
card_id varchar(20) unique,
name varchar(8) not null,
money float(10,2) default 0
);
insert into account values(‘1′,’1234567890′,’张三‘,1000);
insert into account (id,card_id,name) values(‘2′,’0987654321′,’张三’);
2.通过事务修改money字段的数据,代码:
start transaction
update account set money=money-100 where card_id= ‘1234567890’;
update account set money=money+100 where card_id= ‘0987654321’;#此处我们故意写错DML语句
commit;
select * from account