Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: foreign key question
Peter Kirk wrote:
> Hi
>
> this is a general question about relational databases, not specific to
> Oracle (I think), so if there is a better place to ask then please let me
> know.
>
> I have a question about constraints/foreign-keys.
>
> For example:
>
> I have table A and table B.
> Table A has a foreign-key column which points to a record in table B.
>
> Is it possible to define this foreign-key so it can either be "null" (that
> is, there is no related record in table B), or (if it has a value) then it
> points to an existing record in table B.
>
> It seems to me I can only define a foreign-key in table A so it must point
> to an existing record in table B - it cannot be "null". I can just not
> define a foreign-key at all - but then I cannot be sure that if there is a
> value it actually points to a record in table B.
>
> Hope you can understand my question.
>
> Thanks,
> Peter
Foreign keys, whether pointing to a primary key or unique constraint allow NULL. Take a look also at syntaxes such as ON DELETE CASCADE and ON DELETE NULL.
-- Daniel A. Morgan University of Washington damorgan_at_x.washington.edu (replace 'x' with 'u' to respond)Received on Fri Mar 11 2005 - 10:32:57 CST
![]() |
![]() |