MYSQL创建表错误与多个外键

时间:2013-08-28 01:21:22

标签: mysql database

我正在尝试创建一个包含多个外键的表,但是收到错误。我不确定我做错了什么,而且我一直在修补它。我确信它的东西很小而且很愚蠢,但是对此表示赞赏。

Create table Order(
order_number INT AUTO_INCREMENT,
product_id INT(11) NOT NULL,
address_id INT(11) NOT NULL,
user_id INT(11) NOT NULL,
quantity INT(3) NOT NULL,
size VARCHAR(20) NOT NULL,
status VARCHAR(20) NOT NULL,
order_date DATE NOT NULL,
PRIMARY KEY (order_number),
FOREIGN KEY (user_id)
REFERENCES User (user_id),
FOREIGN KEY (product_id)
REFERENCES Product (product_id),
FOREIGN KEY (address_id)
REFERENCES Address (address_id)
)ENGINE = INNODB

我得到的具体错误是:

 #1064 - 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(

order_number INT AUTO_INCREMENT, product_id INT(11)NOT NULL, 地址1'在第1行

1 个答案:

答案 0 :(得分:0)

您不能像这样使用order,因为它也是关键字;加入引号:

Create table `Order`(
order_number INT AUTO_INCREMENT,
product_id INT(11) NOT NULL,
address_id INT(11) NOT NULL,
user_id INT(11) NOT NULL,
quantity INT(3) NOT NULL,
size VARCHAR(20) NOT NULL,
status VARCHAR(20) NOT NULL,
order_date DATE NOT NULL,
PRIMARY KEY (order_number),
FOREIGN KEY (user_id)
REFERENCES User (user_id),
FOREIGN KEY (product_id)
REFERENCES Product (product_id),
FOREIGN KEY (address_id)
REFERENCES Address (address_id)
)ENGINE = INNODB