My first programming program is an Oracle Database graduate certificate program, and the textbook is not Oracle friendly in some places (it is a generic database textbook). I had to rewrite the CREATE table commands and what I came up with is written below.
The tables are created in my database, and I can insert values into the vendor table; however, every time I insert values into the product table I receive the ORA-02291 integrity error
.
I realize that the parent key is not being found in the vendor table, but I am at a loss as to why. I have tried a combination of column and table constraints on both tables, and nothing works. If someone could help me set up this relationship so I can practice that would be great!
CREATE TABLE VENDOR(
V_CODE INTEGER NOT NULL CONSTRAINT VENDOR_P_K PRIMARY KEY,
V_NAME VARCHAR(35) NOT NULL,
V_CONTACT VARCHAR(25) NOT NULL,
V_AREACODE CHAR(3) NOT NULL,
V_PHONE CHAR(8) NOT NULL,
V_STATE CHAR(2) NOT NULL,
V_ORDER CHAR(1) NOT NULL
);
----------------------------------------------------------------------------
CREATE TABLE PRODUCT(
P_CODE VARCHAR2(10) CONSTRAINT PRODUCT_P_CODE_PK PRIMARY KEY,
P_DESCRIPT VARCHAR2(35) NOT NULL,
P_INDATE DATE NOT NULL,
P_QOH NUMBER NOT NULL,
P_MIN NUMBER NOT NULL,
P_PRICE NUMBER(8,2) NOT NULL,
P_DISCOUNT NUMBER(5,2) NOT NULL,
V_CODE INTEGER NOT NULL,
CONSTRAINT V_CODE_FK FOREIGN KEY (V_CODE) REFERENCES VENDOR (V_CODE)
);
EDIT
INSERT INTO VENDOR 2
VALUES (21225, 'Bryson, Inc.', 'Smithson', '615','223-3234','TN','Y');
INSERT INTO VENDOR 2
VALUES (21226,'Superloo, Inc.','Flushing','904','215-8995','FL','N');
INSERT INTO PRODUCT 2
VALUES ('11QER/31','Power painter, 15 psi., 3-nozzle','03-Nov-13',8,5,109.99,0.00,25595);