码迷,mamicode.com
首页 > 数据库 > 详细

mysql数据库操作记录持续更新...

时间:2019-02-22 18:17:35      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:and   方案   子查询   mysql数据库   level   index   eai   info   set   

1.查看删除数据库表的唯一约束 

SHOW INDEX FROM tbl_name (唯一约束也是索引)
ALTER TABLE tbl_name DROP INDEX index_name

  

 
2.update where中不能使用子查询,解决方案如下:

 将子查询作为一张表放在前面

UPDATE `areainfo` a,  (
    SELECT code  FROM `areainfo` where level = 1
) b SET a.`level` =2  WHERE a.`parent_code`  = b.code
  
UPDATE `areainfo` a,  (
    SELECT code, name  FROM `areainfo` where level = 1
) b SET a.`fullName` =concat(b.name,‘,‘,a.name) WHERE a.`parentCode`  = b.code and a.level = 2
 
UPDATE `areainfo` a,  (
    SELECT code, name,parentCode  FROM `areainfo` where level = 2
) b , (
    SELECT code, name  FROM `areainfo` where level = 1
) c SET a.`fullName` =concat(c.name,‘,‘,b.name,‘,‘,a.name) WHERE a.`parentCode`  = b.code and b.`parentCode`  = c.code and a.level = 3 

  

 

mysql数据库操作记录持续更新...

标签:and   方案   子查询   mysql数据库   level   index   eai   info   set   

原文地址:https://www.cnblogs.com/zarawu/p/10419845.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!