sqloracle

Two tables reference each other: How to insert row in an Oracle database?


I have two tables

  1. Department
  2. Professor

in which Department has an attribute called HeadID referencing Professor and Professor has an attribute called DeptID referencing Department

They form a circular relationship.

But the problem is that, how to insert a row to any of these tables?

Oracle complained "parent key not found" after I tried insert a row.


Solution

  • You can define one of the foreign key constraints as DEFERRABLE and defer constraint checking until the end of your transaction (instead of checking at the end of the statement, which ends with "parent key not found"). Read here.