Answer the question
In order to leave comments, you need to log in
How to organize referential integrity on 2 fields in mysql?
Hello. Question such: There are 2 tables test_question and test_question_category. They have common fields test_id and question_id. In the first table they are a composite key, in the second table they are part of the composite key (it also includes test_category_id)/
Foreign key constraints are set, but they work separately. Here is a screenshot:
How to make it work as it should? (so that data integrity is not violated and an error occurs when adding such a combination to test_question_category)? Thank you.
Answer the question
In order to leave comments, you need to log in
https://dev.mysql.com/doc/refman/5.7/en/create-tab...
foreign key (test_id, question_id)
references test_question(test_id, question_id)
on delete cascade
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question