Using NULL values for Foreign Keys

  • Hi all, I have a table, Issues, that also has a column named 'CauseUID' that is a Foreign key to the 'Causes' table. It is not always possible/known what the cause is to an Issue in the 'Issues' table, so for rows in the 'Issues' table that don't have a cause 'CauseUID', do I put a NULL value in this column, or a a '0' value?

    Thanks

    Tryst

  • Best bet is Null. With 0 you are just creating a substituion which could in theory become valid at some point.

  • NULL is not better, it's ONLY RIGHT option.

    To use '0' instead of NULL you need either drop FK constraint or create dummy record with ID = '0' in 'Causes' table.

    Both options are not acceptable for so many reasons it may take too much time to list them here and than read it.

    _____________
    Code for TallyGenerator

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply