mysql-两表级联同步更新两个表中的一列数据

项目说明:

近期我们所做的一个项目有以下的需求:表1:search_tutor  表2:pro_money_info

已知:search_tutor 其中一个字段的有一个导师的项目卡的余额:xmye

          pro_money_info  其中也有一个字段:xmye

但是只有search_tutor里面的数据是从权威的地方拉过来的(财务处),所以项目xmye,在search_tutor进行更新时,那么pro_money_info 也要进行相应的更新,这就需要两个表的级联操作,同时更新这个字段的数据。

我们的两个表都是这个数据库里面的表:yjs_zyjt(数据库名)

业务实现:


 delimiter //
create procedure test()
    begin
        update yjs_zyjt.pro_money_info p,yjs_zyjt.search_tutor_project s set p.XMYE = s.XMYE where s.GH = p.XMFZRGH and s.XMKH = p.XMKH;
    end//
delimiter ;
# 设置定时器
drop event if exists test_event;
create event test_event
on schedule every 1 minute
STARTS now()
do call test();
# 打开定时器
show variables like 'event_scheduler';
set global event_scheduler='on';

每一分钟执行一次,级联更新的操作。



如果想要关闭定时器:
# 清除定时器数据
drop event if exists truncate_event;
create event truncate_event
on schedule every 1 week
do truncate a;
# 关闭数据库的无主键无法更新模式
SET SQL_SAFE_UPDATES = 0;


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值