mysql - MySQL 语法中的表键错误

标签 mysql error-handling syntax-error

有人可以帮我解决我的错误吗?

-- Create ordered
CREATE TABLE ordered(
orderID TINYINT UNSIGNED AUTO_INCREMENT,
total_cost DECIMAL(10,2),
customerID TINYINT UNSIGNED,
offercode VARCHAR(15),
CONSTRAINT ordered_pk PRIMARY KEY (orderID)
CONSTRAINT ordered_customerID_fk FOREIGN KEY (customerID) REFERENCES customer(customerID) 
    ON UPDATE CASCADE
CONSTRAINT ordered_offercode_fk FOREIGN KEY (offercode) REFERENCES offer(offercode)
    ON UPDATE CASCADE
);


DESCRIBE ordered;



-- Create line item
CREATE TABLE line_item(
item_number TINYINT UNSIGNED,
orderID TINYINT UNSIGNED,
quantity TINYINT,
shipping_amount DECIMAL(6,2)
CONSTRAINT line_item_pk PRIMARY KEY (item_number, orderID)
CONSTRAINT line_item_item_number_fk FOREIGN KEY (item_number) REFERENCES item(item_number)
    ON UPDATE CASCADE,
CONSTRAINT line_item_orderID_fk FOREIGN KEY (orderID) REFERENCES ordered(orderID)
    ON UPDATE CASCADE
    ON DELETE CASCADE
);

DESCRIBE line_item;

我的 customerID 外键的 ORDERED 表出现错误,而我的 line_item 表的主键出现错误。

谢谢!

最佳答案

您的第一个错误是因为 customer 表不存在。

第二个错误是因为这一行shipping_amount DECIMAL(6,2),在结尾处添加了一个逗号shipping_amount DECIMAL(6,2),

即使您会遇到主键错误,您也会遇到 item 表错误,因为它不存在。

关于mysql - MySQL 语法中的表键错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33810881/

相关文章:

tensorflow - 使用Python聊天机器人和Face进行应用程序的深度学习。演示代码中的语法错误

r - R :par(cex.lab=2) doesn't work in plot(effect(),…)

jquery - 当用户点击刷新时处理ajax错误

php - 在PHP中的另一个页面中显示输出结果

php - 连接两个页面返回重复的结果

javascript - AngularJS:服务器端记录客户端错误

syntax-error - 语法错误和解析错误之间的区别

mongoose - 最新版本的 mongoose-validator(1.3 或 1.3.2)给出了 SyntaxError

mysql - 数据库设计 - 数据库中的存储选择

mysql - 'product_variation_order.quantity' 中的未知列 'field list' ”