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