Jump to content

Recommended Posts

Hey guys

I've started using SQL and am having a weird problem I'm using two different Tables One has FOREIGN KEYS pointing to the other but whenever I try to insert data into the table with foreign keys I keep triggering Parent Key Constraints, I know that I have all Parent keys entered can someone please take a look and see what they think is the problem?

 

This is the Table with Parent Keys

CREATE TABLE Item
( 	ItemCode Varchar2(6),
Description Varchar2(50),
RetailPrice Number(6,2),
Weight Number(4,1),
PurchasePrice Number(6,2),
Category Varchar2(20),
CONSTRAINT Item_Weight_Check CHECK (Weight <= 60),
    PRIMARY KEY (ItemCode) );
  
  INSERT INTO Item (ItemCode,Description,RetailPrice,Weight,PurchasePrice,Category) VALUES ('A10','Hammock',85,12,40,'Outdoor');
  INSERT INTO Item (ItemCode,Description,RetailPrice,Weight,PurchasePrice,Category) VALUES ('A11','GlitzBBQ',999,55,350,'Luxury');
  INSERT INTO Item (ItemCode,Description,RetailPrice,Weight,PurchasePrice,Category) VALUES ('A13','TableTennisBat',29,0.2,9.5,'Sport');
  INSERT INTO Item (ItemCode,Description,RetailPrice,Weight,PurchasePrice,Category) VALUES ('A15','BasketballRing',150,25,45,'Sport');
  INSERT INTO Item (ItemCode,Description,RetailPrice,Weight,PurchasePrice,Category) VALUES ('A16','WigglesBasketball',25,1.4,9.2,'Sport');
  INSERT INTO Item (ItemCode,Description,RetailPrice,Weight,PurchasePrice,Category) VALUES ('A18','TigerAutographedPutter',499,2.1,250,'Outdoor');
  INSERT INTO Item (ItemCode,Description,RetailPrice,Weight,PurchasePrice,Category) VALUES ('A22','12TigerGolfBalls',35.95,1.5,20,'Sport');
  INSERT INTO Item (ItemCode,Description,RetailPrice,Weight,PurchasePrice,Category) VALUES ('A27','8cmCandle',5,0.5,0.58,'Outdoor');
  INSERT INTO Item (ItemCode,Description,RetailPrice,Weight,PurchasePrice,Category) VALUES ('A30','Setof4outdoor glasses',10,1,2.65,'Outdoor');
  INSERT INTO Item (ItemCode,Description,RetailPrice,Weight,PurchasePrice,Category) VALUES ('A35','16cmCandle',25,1,1.5,'Outdoor');
  

 

Table with Foreign Keys

CREATE TABLE OrderLine
(	Qty Number,
SalePrice Number(6,2),
OrderNo     Number,
ItemCode  Varchar2(6),
Description Varchar2(50),
CONSTRAINT OrderLine_Quantity_Check CHECK (Qty <= 200),

  PRIMARY KEY (OrderNo,ItemCode),
  Foreign Key (OrderNo) References SalesOrder,
  Foreign Key (ItemCode) References Item, 
  Foreign Key (Description) References Item );
  
  
  INSERT INTO OrderLine(OrderNo,ItemCode,Qty,SalePrice,Description) VALUES (501,'A10',1,85,'Hammock');
  INSERT INTO OrderLine(OrderNo,ItemCode,Qty,SalePrice,Description) VALUES (501,'A13',4,29,'TableTennisBat');  
  INSERT INTO OrderLine(OrderNo,ItemCode,Qty,SalePrice,Description) VALUES (501,'A27',6,5,'8cmCandle');  
  INSERT INTO OrderLine(OrderNo,ItemCode,Qty,SalePrice,Description) VALUES (502,'A11',1,999,'GlitzBBQ');
  INSERT INTO OrderLine(OrderNo,ItemCode,Qty,SalePrice,Description) VALUES (503,'A10',10,85,'Hammock');
  INSERT INTO OrderLine(OrderNo,ItemCode,Qty,SalePrice,Description) VALUES (503,'A27',100,4.5,'8cmCandle');
  INSERT INTO OrderLine(OrderNo,ItemCode,Qty,SalePrice,Description) VALUES (504,'A15',2,85,'BasketballRing');
  INSERT INTO OrderLine(OrderNo,ItemCode,Qty,SalePrice,Description) VALUES (504,'A27',12,5,'8cmCandle');
  INSERT INTO OrderLine(OrderNo,ItemCode,Qty,SalePrice,Description) VALUES (505,'A11',1,900,'GlitzBBQ');
  INSERT INTO OrderLine(OrderNo,ItemCode,Qty,SalePrice,Description) VALUES (505,'A18',1,450,'TigerAutographedPutter');
  INSERT INTO OrderLine(OrderNo,ItemCode,Qty,SalePrice,Description) VALUES (506,'A27',10,4.7,'8cmCandle');
  INSERT INTO OrderLine(OrderNo,ItemCode,Qty,SalePrice,Description) VALUES (506,'A30',4,9.5,'Setof4outdoorglasses');
  INSERT INTO OrderLine(OrderNo,ItemCode,Qty,SalePrice,Description) VALUES (506,'A22',2,35,'12TigerGolfBalls');
  

 

Link to comment
https://forums.phpfreaks.com/topic/233870-parent-key-errors/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.