B
B
Bodrosh2017-06-25 01:16:23
MySQL
Bodrosh, 2017-06-25 01:16:23

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:
7fc7709b6b674484a63eff4538a4aa8c.jpg
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

1 answer(s)
E
egor_nullptr, 2017-06-25
@egor_nullptr

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 question

Ask a Question

731 491 924 answers to any question