首页 > 代码库 > mysql同时修改2个表思路
mysql同时修改2个表思路
1.需求:修改评论表中的昵称为手机号码最后4位。
UPDATE trans_eval SET issuer_name = MID(issuer_name,4,6) WHERE CHAR_LENGTH(issuer_name) = 11 AND issuer_name LIKE ‘1%‘;
2.由于误操作(MID(issuer_name,4,6)是中间的6位),需要数据回滚。
3.建立中间表(AND 1<>1 条件不符合建立空表)
CREATE TABLE tmp SELECT T2.REG_NO,T2.MOBILE,t1.`issuer_name` FROM trans_eval t1,member t2 WHERE t1.issuer_no =t2.`reg_no` AND MID(t2.`mobile`,4,6) =t1.`issuer_name` AND 1<>1 GROUP BY T2.REG_NO,T2.MOBILE,t1.`issuer_name` ;
4.导入数据到中间表
INSERT INTO tmp SELECT T2.REG_NO,T2.MOBILE,t1.`issuer_name` FROM trans_eval t1,member t2 WHERE t1.issuer_no =t2.`reg_no` AND MID(t2.`mobile`,4,6) =t1.`issuer_name` GROUP BY T2.REG_NO,T2.MOBILE,t1.`issuer_name` ;
5.数据恢复
SELECT * FROM tmp;UPDATE tmp t1,trans_eval t2 SET t2.`issuer_name`=t1.`MOBILE` WHERE t1.`REG_NO`=t2.`issuer_no`;
mysql同时修改2个表思路
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。