Y
Y
yurygolikov2017-03-14 22:52:03
MySQL
yurygolikov, 2017-03-14 22:52:03

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

3 answer(s)
R
Rsa97, 2017-03-15
@yurygolikov

In MySQL, NULL != NULL, so there can be any number of NULLs in a column with a UNIQUE index.

O
Optimus, 2017-03-14
Pyan @marrk2

No, these are conflicting requirements (mutually exclusive)

A
Artem0071, 2017-03-15
@Artem0071

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 question

Ask a Question

731 491 924 answers to any question