I have a many to many relationship between student and classes.
I created another table (junction table) called student_classes to hold the primary key of student and priamry key of class, this enables a many to many relationship to be modelled as standard database design.
I also have another table called books, this has core books for a specific classes.
A student can choose which one of the core books he/she wants to use for a class. I was going to add it to the classes table but the choice of book depends on the student.
Then I thought it would be ideal if Ii could map it onto the junction table – it seemed logical, as a core book depends not only on the student but on the class.
Would this be good design to have the junction table hold another key to the book?
So tables :
[student]
stduent_id
[classes]
classes_id
[book]
book_id
[student_classes]
student_id
classes_id
book_id
In this model (as per your description) student can use only one book for a given subject, if you need more than one, then move
BookIDinto the primary key of theStudentBooktable. Note that there are two foreign keys inStudentBooktable:FK1 {StudentID, SubjectID}andFK2 {SubjectID, BookID}.