mysql 外键批量更新

    |     2017年10月6日   |   学习偶记   |     评论已关闭   |    3917

这里的外键批量更新,不是innoDB方式的那种级联删除和更新。。

是A表中的某个列和B表关联,然后修改A表中的另外一个和B表关联的列值。即:更新A表的某一列值为B表的某一列值

更新 A表 as a set 列名 = (选择 列名 from B表 where B表的id = a.A表的b表id);

示例:update member m set person_task = (select person_task from mobile_type where id = m.b_id);

另外两种方法:

Solution 1: 修改1列

update student s, city c
set s.city_name = c.name
where s.city_code = c.code;

Solution 2: 修改多个列
update a, b
set a.title=b.title, a.name=b.name
where a.id=b.id

 

噢!评论已关闭。