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','IN_HOUSE','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','PERFECT','NO',4123024,41260);
While inserting the values in this table error occurred.and after adding constraints it’s not working on that condition too. What to do??
Advertisement
Answer
When you have defined relationship then data should be present in Parent table first before inserting the data in child table otherwise data in child table is called as orphan and system will not allow you to store orphan data.
Values in child data 41261 onwards are not present in parent table i.e.Purchase_Supplier