Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle optional relationship

What is the proper way to define an oracle table who has an optional foreign key relationship with another table? For instance, some employee records have defined the country they are from (a FK from countries table), and some have not.

like image 638
user112799 Avatar asked Jul 27 '09 20:07

user112799


1 Answers

Just allow the column to be nullable (don't make it NOT NULL) and create your foreign key as normal. The database will enforce the foreign key for any rows that contain a value in that row, but nothing will be enforced if the row is null.

like image 89
Adam Batkin Avatar answered Sep 20 '22 00:09

Adam Batkin