a paradox

  • 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 ?

  • Can you give us an example with sample data???...involving parent and child data (+ table DDL?)

  • If the foreign key is null, does not this just indicate an orphaned child?

  • Yup.  that can happen if you need to keep "deleted" data in an archive table or even in the main table.

  • 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