上一篇 下一篇 分享链接 返回 返回顶部

香港vps的mysql怎么使用事务修改表

发布人:欢子 发布时间:2026-01-21 15:03 阅读量:9
香港vps的mysql使用事务修改表的示例:

1.新建一个表,代码:

createtableaccount(

idchar(10)primarykey,

card_idvarchar(20)unique,

namevarchar(8)notnull,

moneyfloat(10,2)default0

);

insertintoaccountvalues('1','1234567890','张三',1000);

insertintoaccount(id,card_id,name)values('2','0987654321','张三’);

2.通过事务修改money字段的数据,代码:

starttransaction

updateaccountsetmoney=money-100wherecard_id='1234567890';

updateaccountsetmoney=money+100wherecard_id='0987654321';#此处我们故意写错DML语句

commit;

select*fromaccount

一诺网络香港免备案专区,提供「香港增强VPS」和「香港特惠VPS」两种类型的高可用弹性计算服务,搭载新一代英特尔®至强®铂金处理器,接入CN2低延时高速回国带宽线路,网络访问顺滑、流畅。机房网络架构采用了BGP协议的解决方案可提供多线路互联融合网络,使得不同网络运营商线路的用户都能通过最佳路由实现快速访问。

目录结构
全文