October 17, 2006 at 5:28 am
a primary key becomes foreign key of the other class.
but i found foreign key could be NULL .
which implies primary key has to be NULL ....but this is contradictory ....a primary key can never be NULL.
so, how we can say a Foreign key can be NULL ?
October 18, 2006 at 2:27 am
Can you give us an example with sample data???...involving parent and child data (+ table DDL?)
October 18, 2006 at 2:30 am
If the foreign key is null, does not this just indicate an orphaned child?
October 18, 2006 at 5:51 am
Yup. that can happen if you need to keep "deleted" data in an archive table or even in the main table.
October 18, 2006 at 7:03 am
A FOREIGN KEY can be null if taken in isolation
A column can be NULL providing ALL the CONSTRAINTS applied to it allow it
So
A column that has a PRIMARY KEY CONSTRAINT cannot be set 'NULL' and cannot be null
A column that has a FOREIGN KEY CONSTRAINT can be set 'NULL' and can be null
But, a column that has a PRIMARY KEY CONSTRAINT and a FOREIGN KEY CONSTRAINT cannot be set 'NULL' and cannot be null
Therefore the correct statement should be
A Foreign key can be NULL providing there is no other CONSTRAINT to prevent it
Far away is close at hand in the images of elsewhere.
Anon.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply