Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would know if can be declared in MySQl to create an index constraints in a table with two foreign key that one can be null. For example cannot be repeated a null foreign key with the other foreign key setted:

first foreign key: 1 second foreign key: 1

first foreign key: 1 second foreign key: null

so this two foreign keys can be saved correctly in the table but if I try to save again

first foreign key: 1 second foreign key: null

I should receive an error from the database. I'm not able to express this control in SQLYog.

Someone have experience on this type of problem?

Thanks in advance.

share|improve this question
Show us all the tables invlolved (SQL code preferred) and explain why you need this. – ypercubeᵀᴹ May 30 '13 at 7:30
...also, what version of MySQL? – Michael - sqlbot May 31 '13 at 2:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.