【mysql】表名或字段名与关键字重名解决方法

如果在一个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`;

错误:
在这里插入图片描述
解决后:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43431218/article/details/130507486