Linux 拨号vps windows公众号手机端

mysql怎么使用事务修改表

lewis 7年前 (2018-12-05) 阅读数 14 #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

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门