在MySQL命令行使用sql语句进行更新操作时,
sql 语句
update article set title=\'百草院子\',desc=NULL,content=\'不久之前\',cate=\'1\',created_at=\'2021-02-15 15:34:21.000\',updated_at=\'2021-02-20 15:56:23.390\' where id=\'5\'
出现如下错误;
Error: ER_PARSE_ERROR: 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 ‘desc=‘从百草园到三味书屋’ content=‘不久之前’ where id=NULL’ at line 1
code: ‘ER_PARSE_ERROR’,
errno: 1064,
sqlMessage:
‘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 ‘desc=NULL,content=‘不久之前’,cate=‘1’,created_at=‘2021-02-15 15:34:21.000’,u’ at line 1’,
sqlState: ‘42000’,
index: 0,
原因
这个提示指的是语法错误
经过仔细检查,之所以报这个错误,是因为列名desc与mysql数据库中的保留字段重复,desc命令可以查看表结构的详细信息,降序排列数据。
解决方案:
修改sql语句,将desc换为其他名称,我这里将其修改为a_desc
update article set title=\'百草院子\',a_desc=NULL,content=\'不久之前\',cate=\'1\',created_at=\'2021-02-15 15:34:21.000\',updated_at=\'2021-02-20 15:56:23.390\' where id=\'5\'
在尝试使用SQL语句更新MySQL数据库时遇到了ER_PARSE_ERROR,原因是列名'desc'与MySQL的保留关键字冲突。解决方法是将列名'desc'替换为'a_desc',避免与系统命令混淆。更新后的正确SQL语句应为:update articles set title='百草院子', a_desc=NULL, content='不久之前', cate='1', created_at='2021-02-15 15:34:21.000', updated_at='2021-02-20 15:56:23.390' where id='5'。
3万+

被折叠的 条评论
为什么被折叠?



