my problem is that i have to make table which will have foreign keys, and one of three foreign keys have to be NOT NULL and rest have to be NULL. Is there anything in MySQL to s开发者_StackOverflow中文版olve it? Michael.
Avoid nullable foreign keys - they have a number of problems and disadvantages. It's generally easier and better to put those columns in separate tables so that you don't have to create nulls for them when no value exists. That ought to be the default approach: Normal Form for each distinct case unless you have some special reason to combine the three columns into one table.
FOREIGN KEY Constraints example:
CREATE TABLE parent
(
id INT NOT NULL, PRIMARY KEY (id)
) ENGINE=INNODB;
CREATE TABLE child
(
id INT, parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id) REFERENCES parent(id)
) ENGINE=INNODB;
精彩评论