Foreign keys and NULL in mySQL

后端 未结 5 1425
小蘑菇
小蘑菇 2021-01-01 15:21

Can I have a column in my values table (value) referenced as a foreign key to knownValues table, and let it be NULL whenever needed, like in the example:

Table: valu

5条回答
  •  误落风尘
    2021-01-01 16:23

    Although you can make foreign key columns nullable I would suggest that it's generally better to design tables without nullable foreign keys. Nulls invariably lead to certain ambiguities and incorrect results but that's doubly a problem if the columns in question are expected to be subject to some constraint.

提交回复
热议问题