关于数据表命名为mysql保留的时候的操作

今天操作数据表的时候,发现order数据表无法进行操作,必须加上反单引号才能进行操作,查了一下原因:

反引号是用来区别mysql关键字的,比如,如果你有一个表名叫select,你就必须写成`select`,因为select是mysql保留字。

反引号是加在数据库名、数据表名和数据表的字段名上面的


例子:

不加反单引号:

mysql> show create table order;
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 'order' at line 1

加了反单引号:

mysql> show create table `order`G;
*************************** 1. row ***************************
       Table: order
Create Table: CREATE TABLE `order` (
  `oid` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单编号',
  `cid` int(11) NOT NULL,
  `pid` int(11) NOT NULL,
  `onum` int(11) NOT NULL,
  PRIMARY KEY (`oid`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
1 row in set (0.00 sec)

反单引号在tab键上面

原文地址:https://www.cnblogs.com/4php/p/4108365.html