Foreign keys and NULL in mySQL

Posted by Industrial on Stack Overflow See other posts from Stack Overflow or by Industrial
Published on 2010-05-10T12:26:25Z Indexed on 2010/05/10 12:44 UTC
Read the original article Hit count: 168

Hi everyone,

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: values

 product     type     value     freevalue
 0           1        NULL      100
 1           2        NULL      25
 3           3        1         NULL

Table: types

 id    name     prefix
 0     length   cm
 1     weight   kg
 2     fruit    NULL

Table: knownValues

id    Type     name
0     2        banana 

Note: The types in the table values & knownValues are of course referenced into the types table.

Thanks!

© Stack Overflow or respective owner

Related posts about mysql

Related posts about database-design