MySql同时更新多条记录的方法

一、MySql同时更新多条记录的方法:
      因为数据库不能同时更新多条记录,所以需要采用一些间接的方法来实现此项功能
      1、可以新建一张临时表,让后将查找需要更新的数据插入临时表中,然后将临时表中的数据同步到需要更新的表中,
       创建临时表: create temporary table temp_table (name varchar(128) not null,  age int not null);
       向临时表中插入数据: create temporary table temp_table select * from table_name   where ...
       同步两个数据表中相同字段的数据:
        insert into table_name(f_user_id) select  t.f_user_id  from temp_table as temp  left  join table_name 
       as table on (table.f_user_id = temp.f_user_id and ...) where ...;

     2、不建立临时表直接更新:
        update table_name as table, temp_table as temp 
       set table.f_update_column  = temp.f_update_column  
       where table.f_user_id  =   temp.f_user_id and ...;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值