create table Inventory( I_FlowerNumber number , I_Location varchar(20), I_Condit
ID: 3871924 • Letter: C
Question
create table Inventory( I_FlowerNumber number , I_Location varchar(20), I_Condition varchar(20), I_Search varchar(40),I_Delete varchar(20), I_Add number,I_Quantity number,PRIMARY KEY (I_FlowerNumber));
create table vendor (V_VendorID VARCHAR(20) ,V_PhoneNumber NUMBER, V_Address VARCHAR(20), V_DirectToStore VARCHAR(10), V_Status VARCHAR(5), V_LastUpdatedBy DATE, V_Password VARCHAR(10), V_LasteUpdateTime TIMESTAMP, PRIMARY KEY(V_VendorID ) );
CREATE TABLE purchase_order (
order_number int NOT NULL,
order_name char(50) NOT NULL,
customer_address char(50),
customer_zip int, customer_city char (50),
order_total varchar(50),
v_vendorID VARCHAR(20),
ITEM_NUMBER int NOT NULL,
CONSTRAINT pk_purchase_order PRIMARY KEY (order_number),
FOREIGN KEY (V_VendorID) REFERENCES vendor(V_VendorID),
FOREIGN KEY (ITEM_NUMBER) REFERENCES Inventory(I_FlowerNumber)
);
I need to answer the question below using the information above. I am having trouble getting the command to work without getting error messages. What am I missing below to make the command work?
insert into purchase_order (order_number, order_name, customer_address , customer_zip, customer_city , order_total,v_vendorID,ITEM_NUMBER)
values (5, 'Happy', '', 8, '', '','123','300');
I also tried
insert into purchase_order (order_number, order_name, customer_address , customer_zip, customer_city , order_total,v_vendorID,ITEM_NUMBER)
values (5, 'Happy',null, 8, null, null,'123','300');
Neither of them worked.
I am getting ORA-02291: integrity constraint violated - parent key not found
Explanation / Answer
Generally this type of error will cause when you try to insert the value because that particular value is not updated back in the original table.
Here you have two foreign key attributes in this insert query which are V_VendorID and ITEM_NUMBER referencing V_VendorID,I_FlowerNumber in Inventory and vendor. Now you are trying you insert data into the purchase_order table. But what ever entries you are trying to insert for V_VendorID and ITEM_NUMBER 123 and 300 are not in the original tables i.e. referencing tables Inventory and vendor.That's why this is giving this error.
To solve this error first insert this '123' and '300' values into the attributes of vendor and Inventory tables then try to execute the same query. It will be successfull this time.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.