Hi I am developing a database in Oracle SQL dev, that is trying to access foriegn keys from another table. I am currently working on the ItemOrdered table which I’ve created with the following CREATE statement
CREATE TABLE ItemOrdered(OrderID varchar2(9) REFERENCES Ords(OrderID),
BeltID varchar2(9) REFERENCES BeltID(BeltID),
Quantity varchar(4) NOT NULL,
PRIMARY KEY(OrderID, BeltID))
As you can See I have the following foriegn keys Ords and BeltID.
Now when I try to run the following statement
INSERT INTO ItemOrdered VALUES(401565981,234489212,'2')
It gives me the following error
violated – parent key not found
02291. 00000 – “integrity constraint (%s.%s) violated – parent key not found”
I have provided my Ords CREATE statement if its needed
CREATE TABLE Ords(OrderID varchar2(9) PRIMARY KEY,
CustomerID varchar(9) REFERENCES Customers(CustomerID),
Expected_Delivery_Date date DEFAULT sysdate NOT NULL,
Actual_Delivery_Date date DEFAULT sysdate NOT NULL,
Payment_Due_Date date DEFAULT sysdate NOT NULL,
Order_Date date DEFAULT sysdate NOT NULL, Price Varchar(10),
Order_Placed varchar2(1) CONSTRAINT OrderPlaced
CHECK(Order_Placed IN('Y','N')) NOT NULL,
Order_Confirmed varchar2(1)
CONSTRAINT Order_Confirmed CHECK(Order_Confirmed IN('Y','N')) NOT NULL,
Order_Completed varchar2(1) CONSTRAINT Order_Completed
CHECK(Order_Completed IN('Y','N')) NOT NULL)
And I have also provided my BeltID CREATE statement
CREATE TABLE BeltID(BeltID varchar2(9) PRIMARY KEY,
BeltLengthID varchar2(9) REFERENCES BeltLength(BeltLengthID),
ColourID varchar2(9) REFERENCES Colour(ColourID),
DesignID varchar2(9) REFERENCES Design(DesignID),ComponentID varchar2(9) REFERENCES Component(ComponentID))
I don’t seem to quite understand why I am getting this error. Is there an clear explanation why?
Here is the http link of what I am trying to do.
link text
Due to the foreign key constraints you specified when you created table ItemOrdered, when you perform this insert:
… the values 401565981 and 234489212 must correspond to key values in the Ords and BelitId tables respectively – i.e. these 2 queries should return rows:
The error message suggests this is not the case.