溫馨提示×

mysql怎么使用事務修改表

小新
181
2020-12-14 19:04:56
欄目: 云計算

mysql怎么使用事務修改表

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

1
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女