Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can Foreign key be Null for some rows?

 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic