Answer the question
In order to leave comments, you need to log in
How to make a foreign key unique, but at the same time, so that it can be NULL?
How to make a foreign key unique, but at the same time, so that it can be NULL?
PS I reformulated my question in a different way: How to build the architecture of tables in my case? .
Answer the question
In order to leave comments, you need to log in
In MySQL, NULL != NULL, so there can be any number of NULLs in a column with a UNIQUE index.
On sql it is hardly realizable. But you can try, if possible, just do a check, for example in php, before writing
. That is, when you want to insert a record, you first need to check in the database, then if the key is not set, then write it down, otherwise give an error
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question