• [Mysql]ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds


    一、问题背景


    需要修改数据库里的数据,修改时报错。


    二、问题 sql

    sql语句如下:

    update userGroup set group = "sh_group,tj_dw_group,tj_admin_group,ferry_data_group" where user= 'heqiriletu';
    

    userGroup表字段如下:

    字段名格式
    uservarchar(200)
    groupvarchar(200)

    三、报错内容

    ERROR 1064 (42000): You have an error in your SQL syntax;
    check the manual that corresponds to your MySQL server version for the right syntax to 
    use near 'group = "sh_group,tj_dw_group,tj_admin_group,ferry_data_group" where user= 'heqi'
    

    四、问题原因

    sql中含有group的关键字,所以需要对关键字需要加上``符号进行转义。

    `这个符号是对数据库名、表明、字段的特殊处理。避免和 mysql 的本身的关键字冲突。


    五、解决方案

    将对 group 字段加入``字符

    update userGroup set `group` = "sh_group,tj_dw_group,tj_admin_group,ferry_data_group" where user= 'heqiriletu';
    

    六、优化建议

    以后建表时,尽量避免使用mysql的关键字作为建表字段。

  • 相关阅读:
    Clam and fish
    费马小定理求逆元模板题
    1
    DP 习题
    106. 从中序与后序遍历序列构造二叉树
    计算几何(判断四边形形状)
    中国剩余定理
    BFS模板
    DFS模板
    线段树
  • 原文地址:https://www.cnblogs.com/erlou96/p/16878353.html
Copyright © 2020-2023  润新知