[英]Improving my database design using TPH Inheritance
This is my current database design, for the moment just look the student, teacher and classes tables. 这是我当前的数据库设计,目前仅查看学生,老师和班级表。
I'm trying to convert some tables into news using TPH Inheritance. 我正在尝试使用TPH继承将某些表转换为新闻。 For example.
例如。
Create a new table called Person where contains: 创建一个名为Person的新表,其中包含:
But is there remaining one field called ClassId
, where it's contained in Student
table. 但是是否还有一个名为
ClassId
字段,它包含在Student
表中。 At this momment I don't know if should I create a join table to store the ClassId
and PersonId
, or just put the ClassId
into the Person
table. 在这一刻,我不知道是否应该创建一个
ClassId
表来存储ClassId
和PersonId
,或者只是将ClassId
放入Person
表中。 That's my big doubt. 那是我最大的疑问。
Where do I have to put the ClassId
field? 我必须在哪里放置
ClassId
字段?
I have to mention that each student can only be in one class, not many. 我不得不提到,每个学生只能参加一个班级,而不是很多班。 Teachers can have many classes as they want.
教师可以根据需要开设许多课程。
I think you didn't model the domain correctly: 我认为您没有对域进行正确建模:
First you must have students regardless of that they have class or not, 首先,无论学生是否上课,都必须有他们,
In current model, it seems that Student is a weak entity and depends on classes. 在当前模型中,学生似乎是一个弱者,并且依赖于阶级。
Courses are also independent of semester classes which might happen this year and don't happen next year. 课程也独立于可能在今年发生而明年不会发生的学期课程。
But if you want to have TPH strategy to model the database this link might be of help to you. 但是,如果您希望使用TPH策略对数据库进行建模,则此链接可能会对您有所帮助。
You will have a Person table, then Teacher table which has a reference to Person, and Student which also has a reference to Person table. 您将有一个Person表,然后有Teacher表,它引用了Person,还有Student,也引用了Person表。
And at last, the student table has a reference to semester courses through a joint table. 最后,学生表通过联合表可以参考学期课程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.