mysql银行储蓄额度格式_mysql创建表用于银行储蓄系统

本文演示了如何使用MySQL创建一个银行储蓄系统表,包括账户ID、账号、姓名和金额字段,并展示了如何插入、修改数据以及实现转账功能。通过事务处理确保转账操作的原子性和一致性,同时给出了回滚点的例子。
摘要由CSDN通过智能技术生成

-- 创建表用于保存账户

create table my_account(

id int unsigned not null primary key auto_increment,

account varchar(16) not null unique,

name varchar(10) not null)charset utf8;

--插入数据

insert into my_account values

(1,"1111111111111111","张三"),

(2,"2222222222222222","李四"),

(3,"3333333333333333","王军");

--修改表

alter table my_account add money decimal(20,2) after name; -- 在姓名后增加存储金额表格

--更新数据

update my_account set money=1000 where id=1;

update my_account set money=1050 where id=2;

update my_account set money=3000 where id=3;    --根据条件修改表中数据

--转账功能

update my_account set money=money-500 where id=2;

--事务操作(1、手动提交,2、自动提交)

--开启事务

start transaction;

--查询功能

select * from my_account; -- 结果是减掉五百的数据(结果是经事务日志处理的)

-- 转账功能

update my_account set money=money+500 where id=1;

--手动转账

commit;

--回滚点

--开启事务

start transaction;

--转账功能

update my_account set money=money-500 where id=2;

update my_account set money=money-500 where id=3;

--设置回滚点

savepoint sp1;

--转账出错

update my_account set money=money-500 where id=3;

--回滚  //返回上一步操作

rollback to sp1;

--转账正确

update my_account set money=money-500 where id=2;

update my_account set money=money+1000 where id=1;

--提交

commit;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值