2 Replies - 3162 Views - Last Post: 04 April 2012 - 12:30 AM

#1 tRose  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 13-April 11

Integrity Constraint Violated - Parent Key Not Found

Posted 04 April 2012 - 12:09 AM

I am having a problem with integrity constraint violation...
REATE TABLE CHARGE (
  CHARGE_CODE           NUMBER (2)              ,
  CHARGE_DESCRIPTION    VARCHAR2 (20)           ,
  CHARGE_FEE            NUMBER  (5, 2)          ,
  CONSTRAINT CHARGE_FEE CHECK (CHARGE_FEE >= 0) ,
  CONSTRAINT CHARGE_CHARGE_CODE_PK PRIMARY KEY (CHARGE_CODE)
  );

 SELECT * FROM CHARGE;

  CREATE TABLE FILM (
    FILM_NUM      NUMBER      (5)                ,
    FILM_TITLE    VARCHAR2    (45)  NOT NULL     ,
    FILM_YEAR     NUMBER      (4)                ,
    FILM_TYPE     VARCHAR2    (3)                ,
    FILM_GENRE    VARCHAR2    (14)               ,
    FILM_COST     NUMBER      (5, 2)             ,
    CHARGE_CODE   NUMBER      (2)                ,

    CONSTRAINT FILM_FILM_NUM_PK PRIMARY KEY (FILM_NUM)  ,
    CONSTRAINT FILM_YEAR CHECK (FILM_YEAR > 1900)       ,
    CONSTRAINT FILM_TYPE CHECK (FILM_TYPE IN ('DVD', 'VHS')),
    CONSTRAINT FILM_CHARGE_CODE_PK FOREIGN KEY (CHARGE_CODE) REFERENCES CHARGE 
    );

  SELECT * FROM FILM;

  INSERT INTO CHARGE (CHARGE_CODE, CHARGE_DESCRIPTION, CHARGE_FEE) VALUES
  (1, 'STANDARD', '2.00');

  INSERT INTO CHARGE VALUES
  (2, 'NEW RELEASE', '3.00');

  SELECT * FROM CHARGE;

  INSERT INTO CHARGE VALUES
  (3, 'DISCOUNTED', '1.50');

  SELECT * FROM CHARGE;

  INSERT INTO FILM (FILM_NUM, FILM_TITLE, FILM_YEAR, FILM_TYPE, FILM_GENRE, FILM_COST, CHARGE_CODE) VALUES
  (1, 'SAW', 2000, 'DVD', 'HORROR', '39.99', 1);  



When I try to run INSERT INTO FILM I GET...

Line - 41 Position - 1 ORA-02291: integrity constraint (CIS337.FILM_CHARGE_CODE_PK) violated - parent key not found.

I was thinking I may need to add...

ON UPDATE CASCADE

to the end of...

CONSTRAINT FILM_CHARGE_CODE_PK FOREIGN KEY (CHARGE_CODE) REFERENCES CHARGE

Anyone able to help me out some? Thanks ahead of time.

Is This A Good Question/Topic? 0
  • +

Replies To: Integrity Constraint Violated - Parent Key Not Found

#2 tRose  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 13-April 11

Re: Integrity Constraint Violated - Parent Key Not Found

Posted 04 April 2012 - 12:21 AM

If I add ON UPDATE CASCADE to line 23 I get an error of
ORA-00905: missing keyword

CREATE TABLE CHARGE (
  CHARGE_CODE           NUMBER (2)              ,
  CHARGE_DESCRIPTION    VARCHAR2 (20)           ,
  CHARGE_FEE            NUMBER  (5, 2)          ,
  CONSTRAINT CHARGE_FEE CHECK (CHARGE_FEE >= 0) ,
  CONSTRAINT CHARGE_CHARGE_CODE_PK PRIMARY KEY (CHARGE_CODE)
  );

 SELECT * FROM CHARGE;

  CREATE TABLE FILM (
    FILM_NUM      NUMBER      (5)                ,
    FILM_TITLE    VARCHAR2    (45)  NOT NULL     ,
    FILM_YEAR     NUMBER      (4)                ,
    FILM_TYPE     VARCHAR2    (3)                ,
    FILM_GENRE    VARCHAR2    (14)               ,
    FILM_COST     NUMBER      (5, 2)             ,
    CHARGE_CODE   NUMBER      (2)                ,

    CONSTRAINT FILM_FILM_NUM_PK PRIMARY KEY (FILM_NUM)  ,
    CONSTRAINT FILM_YEAR CHECK (FILM_YEAR > 1900)       ,
    CONSTRAINT FILM_TYPE CHECK (FILM_TYPE IN ('DVD', 'VHS')),
    CONSTRAINT FILM_CHARGE_CODE_PK FOREIGN KEY (CHARGE_CODE) REFERENCES CHARGE ON UPDATE CASCADE
    );

  SELECT * FROM FILM;

  INSERT INTO CHARGE (CHARGE_CODE, CHARGE_DESCRIPTION, CHARGE_FEE) VALUES
  (1, 'STANDARD', '2.00');

  INSERT INTO CHARGE VALUES
  (2, 'NEW RELEASE', '3.00');

  SELECT * FROM CHARGE;

  INSERT INTO CHARGE VALUES
  (3, 'DISCOUNTED', '1.50');

  SELECT * FROM CHARGE;

  INSERT INTO FILM (FILM_NUM, FILM_TITLE, FILM_YEAR, FILM_TYPE, FILM_GENRE, FILM_COST, CHARGE_CODE) VALUES
  (1, 'SAW', 2000, 'DVD', 'HORROR', '39.99', 1);        


Was This Post Helpful? 0
  • +
  • -

#3 tRose  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 13-April 11

Re: Integrity Constraint Violated - Parent Key Not Found

Posted 04 April 2012 - 12:30 AM

I figured it out. Apparently, I did not execute lines 28, 31, and 36. Once I did it worked fine.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1