如果在一个sql业务中,你见到如下字段:
date,for,check,while,end,long等作为了表名或者字段名,那么sql执行肯定会有异常信息!
代码:
SELECT for,long FROM table;
报错:
1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use
near 'for,long FROM table' at line 1
解决
其实很简单,我们可以使用特定符号告诉mysql这是自己表或者字段的名字就可以了,那么开发者和mysql之间有一个约定就可以解决了。
这一约定就是 ``
如下:
SELECT `for`,`long` FROM `table`;
错误:
解决后: