wood burning stoves*
The moose likes JDBC and the fly likes Can Foreign key be Null for some rows? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Can Foreign key be Null for some rows?" Watch "Can Foreign key be Null for some rows?" New topic
Author

Can Foreign key be Null for some rows?

Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
I have a parent table and a child table. The child table has a foreign key relationship to the parent table.

The issue is that there could be some rows in the child table where the foreign key could be NULL. Is that possible in Oracle 9i?
Can the foreign key hold a null value?

Any ideas would be appreciated.

thanks,
Vish
Santosh Maskar
Ranch Hand

Joined: Jul 02, 2003
Posts: 226
hi
in case of master details ,
your parent table is holding the primary key and you are refernig this priamry key , as a forign key in child table , if this is te case then it is not possible ,

if you are able to inserth the null in parent table then you can do this
but as per my guess you can not insert the null i primary key ,

but you can define the unique key intead of defining the primar key. then it accept the null value.
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Thanks Santosh,
One of the guys working in the project has come out with this idea of having a special row in the parent table having all - (hyphens).
This would allow the rows in the child table to contain - (hyphen) value in the foreign key column for those rows which do not have a valid foreign key.
The business layer would interpret the - (hyphen) differently.

This idea is also appealing to me.
 
Consider Paul's rocket mass heater.
 
subject: Can Foreign key be Null for some rows?