gpt4 book ai didi

mysql - 无法添加或更新子行

转载 作者:可可西里 更新时间:2023-11-01 07:10:54 24 4
gpt4 key购买 nike

我正在尝试将记录添加到下面的两个表中,

CREATE TABLE customer
(Custno CHAR(3),
Custname VARCHAR(25) NOT NULL,
Custstreet VARCHAR(30) NOT NULL,
Custcity VARCHAR(15) NOT NULL,
Custprov VARCHAR(3) NOT NULL,
Custpcode VARCHAR(6) NOT NULL,
Disc DECIMAL(3,1),
Balance DECIMAL(7,2),
Credlimit DECIMAL(5),
Srepno CHAR(3),
CONSTRAINT pkcustno PRIMARY KEY (Custno),
CONSTRAINT fksrepno FOREIGN KEY (Srepno) REFERENCES salesrep(Srepno)
);


CREATE TABLE orders
(Orderno CHAR(5) UNIQUE NOT NULL,
Orderdate DATE,
Custno CHAR(3) NOT NULL,
CONSTRAINT fkordercust FOREIGN KEY (Custno) REFERENCES customer (Custno)
);

这样添加时,

INSERT INTO orders(Orderno, Orderdate, Custno) VALUES('14587','2011-11-09', '125' );
INSERT INTO orders(Orderno, Orderdate, Custno) VALUES('11547','2011-11-07', '125' );

我得到,“无法添加或更新子行:外键约束失败(shorders,CONSTRAINT fkordercust 外键 (Custno) REFERENCES customer (Custno))“ table 有问题吗?

最佳答案

您没有 CustNo = '125' 的客户。因此,外键 失败。您正在尝试为不存在的客户下订单,数据库抛出错误。

关于mysql - 无法添加或更新子行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8252121/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com