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
Comment