ORA-02291: integrity constraint (STARTUP.SUPER_SSN_FK) violated - parent key not foun

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AKERMAN1
    New Member
    • Mar 2014
    • 1

    ORA-02291: integrity constraint (STARTUP.SUPER_SSN_FK) violated - parent key not foun

    Code:
    CREATE TABLE EMPLOYEE
    ( Fname VARCHAR2(25) NOT NULL,
    Lname VARCHAR2(25) NOT NULL,
    Ssn CHAR(9) CONSTRAINT SSN_PK PRIMARY KEY,
    DOB DATE,
    Address VARCHAR2(30),
    Sex CHAR,
    Salary DECIMAL(10,2),
    Super_ssn CHAR(9),
    DEPT_ID  NUMBER 
     );
    
    Table created.
    
    ALTER TABLE EMPLOYEE
    ADD CONSTRAINT DEPT_ID_FK FOREIGN KEY (DEPT_ID) REFERENCES DEPARTMENT (DEPT_ID) 
    ADD CONSTRAINT SUPER_SSN_FK FOREIGN KEY (Super_ssn) REFERENCES EMPLOYEE (SSN) ;
    
    
    CREATE TABLE DEPARTMENT
    ( DEPT_NAME VARCHAR2(25) UNIQUE NOT NULL,
    DEPT_ID NUMBER CONSTRAINT DEPT_ID_PK PRIMARY KEY,
    MGR_SSN CHAR(9) NOT NULL,
    Mgr_start_date DATE);
    
    Table created.
    
    ALTER TABLE DEPARTMENT
    ADD CONSTRAINT DEPT_MGR_FK FOREIGN KEY (MGR_SSN) REFERENCES EMPLOYEE(SSN);
    
    SQL> insert into department
      2  values('sales',0002,'24-march-1988','123456789');
    insert into department
    *
    ERROR at line 1:
    ORA-02291: integrity constraint (STARTUP.DEPT_MGR_FK) violated - parent key not
    found
    SQL> INSERT INTO EMPLOYEE
      2  VALUES('JOHN','SMITH',123456784,'20-JUNE-1976','24,MONGROMERY','M', 4000,123456789,1);
    INSERT INTO EMPLOYEE
    *
    ORA-02291: integrity constraint (STARTUP.SUPER_SSN_FK) violated - parent key not found
    Last edited by Rabbit; Mar 9 '14, 11:48 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I'm not sure what your question is. The error is pretty clear, you're violating the foreign keys you set up. When you set up a foreign key, the foreign key must exist when you insert that record. The foreign key records don't exist, that's why you're getting the error.

    Comment

    Working...