sql语句缺少倒引号导致的问题

        也真是奇葩, 这么个简单的问题, 居然花费好几分钟才看出来, 来看下:

mysql> desc tb_xxx;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| group | varchar(1024)    | NO   |     |         |                |
| type  | varchar(1024)    | NO   |     |         |                |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.14 sec)

        然后准备这么塞数据:

mysql> insert into area_info set group = "hello" ;
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 = "hello"' at line 1
mysql> 

        然后就呵呵哒了, 为什么呢? 原来group是关键字啊, 加倒引号就可以解决问题。

        其实, 在建表的时候, 最好提前避免与关键字冲突。

猜你喜欢

转载自blog.csdn.net/stpeace/article/details/81709063