Can a normalised database have 2 link tables linking 2 other tables to a single primary key in another?

StackOverflow https://stackoverflow.com/questions/21229492

  •  30-09-2022
  •  | 
  •  

문제

Here are the tables that I currently have:

Student(StudentID, SurName, OtherNames, TargetGrade etc.)
Teacher(TeacherID, SurName, OtherNames etc.)
Class(ClassID, Description)

A student can be in multiple classes and each class has many students. A Class can have multiple teachers and each teacher teaches many classes. So to deal with these 2 many to many relationships, I used 2 lookup tables:

StudentClass(StudentID,ClassID)
TeacherClass(TeacherID,ClassID)

The reason why I am not sure whether this is normalised is because if you remove the class table (Which seems a little redundant but could help with the identification of classes), you would be left with a many to many relationship between StudentClass and TeacherClass. Is this Normalised?

Thanks

-----------        ----------       ----------         -------------         -----------
|         |       /|        |\      |        |        /|           |\        |         |
| Student |------<-| Student|->-----|  Class |-------<-| Class -   |->-------| Teacher |
|         |       \| -Class |/      |        |        \|   Teacher |/        |         |
-----------        ----------       ----------         -------------         -----------

Edit: For this system Class would not be required to store anything other really than a description. Test Scores are stored in a separate table linked to students.

도움이 되었습니까?

해결책

What you have here is definitely in 3rd NF. Just a remark concerning what you are saying about scores: you should not miss the fact that each class is associated to 1 or many exams, so you have typically a one-to-many relation between class and exams (could be 0 to many for classes without exams?).

Then, you can consider that a score is held by a relation\table between the 'studentClass' table and the 'Exams' table. Depending on your business rules, a 'studentClass' record can be linked to one or multiple scores for a specific exam, depending if you can pass the exam once or multiple times.

다른 팁

Since the data model you have described has two many-to-many relationships viz., --A student can be in multiple classes and each class has many students. --A Class can have multiple teachers and each teacher teaches many classes.

it is fair to use two linking tables, rather than sticking to normalize it making the modelling process bit more complex.

There is no harm in normalizing it further, but complexity in the model is unavoidable

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top