I have a data model which is as follows …
- A Topic can have multiple Exercises (ExerciseTopic(FK) references TopicId(PK))
- An Exercise can have multiple Questions (Exercise(FK) references ExerciseId(PK))
- A Question can have multiple (4) AnswerChoices

I would like to have a three part primary key for AnswerChoices table as it is this combination that will uniquely identify each choice.
- Will I need a foreign key in AnswerChoices table for data integrity purposes or
- Will the composite primary key be sufficient? If the foreign key is required, will it be two part composite foreign key (ExerciseId, QuestionId)?
Sample data …
- Topic (T1)
- Exercise E1
- Question 1 (AnswerChoices: a, b, c, d)
- Question 2 (AnswerChoices: a, b, c, d)
- Question 3 (AnswerChoices: a, b, c, d)
- Exercise E2
- Question 1 (AnswerChoices: a, b, c, d)
- Question 2 (AnswerChoices: a, b, c, d)
- Question 3 (AnswerChoices: a, b, c, d)
- Exercise E3
- Question 1 (AnswerChoices: a, b, c, d)
- Question 2 (AnswerChoices: a, b, c, d)
- Question 3 (AnswerChoices: a, b, c, d)
- Exercise E1
- Topic (T2)
- Exercise E1
- Question 1 (AnswerChoices: a, b, c, d)
- Question 2 (AnswerChoices: a, b, c, d)
- Question 3 (AnswerChoices: a, b, c, d)
- Exercise E2
- Question 1 (AnswerChoices: a, b, c, d)
- Question 2 (AnswerChoices: a, b, c, d)
- Question 3 (AnswerChoices: a, b, c, d)
- Exercise E3
- Question 1 (AnswerChoices: a, b, c, d)
- Question 2 (AnswerChoices: a, b, c, d)
- Question 3 (AnswerChoices: a, b, c, d)
- Exercise E1
It looks like you’ll need a four-column key in AnswerChoices: {TopicID, ExerciseID, QuestionID, ChoiceID}. And the table “AnswerChoices” should have a
foreign key (TopicID, ExerciseID, QuestionID) references Questions (TopicID, ExerciseID, QuestionID).