问题描述
CREATE TABLE Purchase_supplier
(
supplier_ID int NOT NULL,NAME varchar(255) NOT NULL,TYPE_OF_supplier varchar(255),STOCK_NAME varchar(255) NOT NULL,TYPE_OF_SUPPLY varchar(255) NOT NULL,CONSTRAINT PU_SU PRIMARY KEY (supplier_ID)
)
INSERT INTO Purchase_supplier
VALUES(41256,'FLYNN SAVIoUR','IN_HOUSE','Desktop','WHOLESALE');
INSERT INTO Purchase_supplier
VALUES(41257,'JOnes LYNN','Mouse','WHOLESALE');
CREATE TABLE Purchase_Supply_Details
( inspection VARCHAR(25) NOT NULL,ITEM_CONDITION VARCHAR(25) NOT NULL,RETURN_STOCK VARCHAR(25) NOT NULL,STOCK_ID INT NOT NULL,CONSTRAINT PSD PRIMARY KEY (supplier_ID,STOCK_ID),supplier_ID int FOREIGN KEY REFERENCES Purchase_supplier(supplier_ID)
);
INSERT INTO Purchase_Supply_Details
VALUES('SAMPLE','PERFECT','NO',4123023,41259);
INSERT INTO Purchase_Supply_Details
VALUES('PIECE',4123024,41260);
在此表中插入值时发生错误。添加约束后,它也不适用于该条件。该怎么办?
解决方法
定义关系后,应先在父表中存在数据,然后再将数据插入子表中,否则子表中的数据称为孤立数据,系统将不允许您存储孤立数据。
父表中不存在子数据41261及更高版本中的值,即 Purchase_Supplier