Foreign keys and NULL in mySQL

后端 未结 5 1424
小蘑菇
小蘑菇 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:14

    This is a 1 to zero-to-many relationship. I have used this many times with SQL Server. I believe it is possible to do this with MySQL as well.

    I prefer to avoid NULLs in my databases because of issues related to data aggregation so, depending on my design, I put an UNKNOWN row in the lookup table.

提交回复
热议问题