I have 5 db tables but the issue I have is with the Student_Answer Table, I do not know if I should include the SessionId field or not in that table because we will know which session each question belongs to through foreign keys. I thought I may as well ask to make sure:
Below are tables:
Session Table
SessionId (auto PK) SessionName
1 DOEEO
2 EFOEO
3 EOEOW
Question Table:
QuestionId (Auto PK) QuestionNo QuestionContent SessionId (Fk)
1 1 Question 1 1
2 2 Question 2 1
3 3 Question 3 2
4 4 Question 4 2
5 5 Question 5 3
Answer Table:
AnswerId (Auto PK) Answer QuestionId(Fk)
1 A 1
2 C 1
3 B 2
4 C 3
5 A 4
6 D 5
7 E 5
Student Table:
StudentId (Auto PK) StudentForename StudentSurname
1 Joe Price
2 Kyle May
3 Mark Knowles
Student_Answer Table:
StudentAnswerId (auto PK) SessionId(FK) QuestionId (FK) StudentAnswer StudentId (FK)
1 1 1 C 1
2 1 1 B 1
3 1 1 A 2
4 1 1 C 2
5 1 2 C 1
6 1 2 B 2
7 2 3 A 1
8 2 3 C 2
Not only do you not need the SessionID field in the StudentAnswer table, you don’t need the StudentAnswerId field either. All you need are the QuestionID, StudentId, and StudentAnswer. Your primary key would be the QuestionId and StudentId.
This is called a many to many relationship.