I am creating a database that is trying to access values from a foreign key. I have created two following tables
CREATE TABLE Component(
ComponentID var
Please post your entire SQLPLUS session so that the error is easily reproducible.
Looks like the insert into the child table is being done before the insert into the parent table which is causing this error.
Change the order of inserts and rerun your code.
SQL> CREATE TABLE TypeComponent(
2 TypeComponentID varchar2(9) PRIMARY KEY,
3 Type_Description varchar2(30)
4 CONSTRAINT Type_Description CHECK(Type_Description IN('Strap', 'Buckle', 'Stud')) NOT NULL
5 )
6 ;
Table created.
SQL> CREATE TABLE Component(
2 ComponentID varchar2(9) PRIMARY KEY,
3 TypeID varchar2(9) REFERENCES TypeComponent(TypeComponentID)
4 )
5 ;
Table created.
SQL> INSERT INTO Component VALUES(192359823,785404309);
INSERT INTO Component VALUES(192359823,785404309)
*
ERROR at line 1:
ORA-02291: integrity constraint (COAMGR.SYS_C002513823) violated - parent key
not found
SQL> INSERT INTO TypeComponent VALUES(785404309, 'Strap');
1 row created.
SQL> INSERT INTO Component VALUES(192359823,785404309);
1 row created.
SQL> commit;
Commit complete.