入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

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

创建时间:2016-03-23 投稿人: 浏览次数:1916
一、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 ...;
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像