mysql> use test;
Database changed
mysql> CREATE TABLE Order
-> (
-> number INTEGER,
-> shippingAddress varchar(100),
-> shippingDate varchar(100),
-> orderID Integer NOT NULL,
-> orderLineItemID Integer,
-> PRIMARY KEY (orderID)
-> )
-> ;
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(
number INTEGER,
shippingAddress varchar(100),
shippingDate varchar(10' at line 1
mysql>
不知道为什么?有人帮我解答下吗??
解决方案 »
order 是保留字,需要用反引号标识 `mysql> CREATE TABLE `Order`
-> (
-> number INTEGER,
-> shippingAddress varchar(100),
-> shippingDate varchar(100),
-> orderID Integer NOT NULL,
-> orderLineItemID Integer,
-> PRIMARY KEY (orderID)
-> );
Query OK, 0 rows affected (0.14 sec)mysql>
mysql> CREATE TABLE Order
-> (
-> `number` INTEGER,
-> shippingAddress varchar(100),
-> shippingDate varchar(100),
-> `orderID` Integer NOT NULL,
-> orderLineItemID Integer,
-> PRIMARY KEY (`orderID`)
-> )
-> ;
我用1楼的代码就解决了。但是为什么 当表的名字是 Order 时建表就不行?? 而表的其他代码不变,我把表名字改了,就可以了。还有:那个“`”是什么用处的?为什么Order加上这个就可以成功建表了???
--转自