背景
開發過程中遇到了遇到了一句sql語句一直報錯,看了一下字段名和表名都對應上了,但是還是一直報錯
sql語句如下:
update table set using = "hh" where id = 2
報錯信息:
[Err] 1064 - 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 'table set using = ""hh where id = 2' at line 1
分析
經過分析,我的sql語句中有關鍵字 table 和 using ,所以是執行失敗的,在sql語句中如果表名和字段名有關鍵字的話,要用Tab鍵上面那個鍵(``)引用一下。
正確寫法:
update `table` set `using` = "hhh" where id = 2
總結
避免在字段名和表名使用關鍵字,如果一定得使用的話要加引用符號
附上mysql5.7保留關鍵字官方文檔:
https://dev.mysql.com/doc/refman/5.7/en/keywords.html