Foreign keys and NULL in mySQL

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

    Of course, there is a possibilities ti have a NULL values in foreign key, but for that you don't get worry about this, I hope you may used InnoDB as database engine to manage the Key constraints. For this case i suggest to use Left Join or Right Join to get rows from DB and Group By can be used for avoid duplication. Please do not use Inner Join.

提交回复
热议问题