我应该如何使关系在此数据库模型中工作

时间:2022-10-05 12:26:40

(I apologies in advance for my English) I need to make a model of relation.

(我提前为我的英语道歉)我需要建立一个关系模型。

Normally it a thing we should do in team, but I am stuck to be alone, so I am kind of overwhelm by this

通常这是我们应该在团队中做的事情,但我坚持独自一人,所以我有点不知所措

It about a school and it information concerning The Student, The Parents and the Class he want to enroll. Also they keep academic results.

关于学校及其想要注册的学生,家长和班级的信息。他们也保持学业成绩。

I just can't get an ideal of how I could link them all and avoiding relations problems

我无法理解如何将它们联系起来并避免关系问题

http://i.imgur.com/fdwxH8g.jpg

http://i.imgur.com/fdwxH8g.jpg

1 个解决方案

#1


0  

First, I suggest you add a Person table to supertype Parent and Student, and move all the personal and contact information attributes to Person. You're sure to want to add additional information later, and having to duplicate everything for parents, students (and later, teachers and other school staff) gets to be a nuisance.

首先,我建议您添加一个Person表到父类和学生的超类型,并将所有个人和联系信息属性移动到Person。您肯定希望以后添加其他信息,并且不得不为父母,学生(以及后来的老师和其他学校员工)复制所有内容,这会让您感到非常麻烦。

person (person_id PK, last_name, first_name, sex, birthday, email, address, city, phone_number, cellphone_number)

Next, do you want to record biological parents or caregivers? In schools we normally care about caregivers and their relationship to the student. To record that, you could create a relationship type table:

接下来,您想记录亲生父母或看护人吗?在学校,我们通常关心照顾者及其与学生的关系。要记录它,您可以创建一个关系类型表:

relationship (relationship_id PK, description)

with entries for father, mother, aunt, grandfather, fostermother, etc. You can then record the relationship between 2 persons like so:

有父亲,母亲,阿姨,祖父,fostermother等条目你可以记录两个人之间的关系,如下所示:

parent (parent_id PK/FK, child_id PK/FK, relationship FK)

If you wanted to record biological parents, you could use:

如果你想记录亲生父母,你可以使用:

bioparents (child_id PK/FK, father_id FK, mother_id FK)

with father and mother ids nullable (or decompose into separate tables for father and mother) since we're unlikely to know both parents for all students.

由于我们不太可能为所有学生都认识父母,所以父亲和母亲的儿童可以*(或分解为父亲和母亲的单独表格)。

Finally, we get to the business at hand, students. Historical information and alumni are important in schools, so take care to model students over time, not just current students. You need to consider the time resolution for student registrations - are registrations annual, quarterly, or something else? For annual registrations, you could start with:

最后,我们到达了手头的企业,学生们。历史信息和校友在学校中很重要,因此要注意随着时间的推移对学生进行建模,而不仅仅是现在的学生。您需要考虑学生注册的时间分辨率 - 是年度,季度还是其他注册?对于年度注册,您可以从以下开始:

student (person_id PK/FK, year)

Now, what is a class? Is it something that recurs over time, or are classes with the same name in different years/quarters separate things? Can classes contain learners of different forms/grades/levels, or are they partitions of those? Is a class a grouping of students that attend multiple subjects, or a subject-specific grouping? I'm familiar with two types of classes, which could be called form classes and academic classes, but things may be different in your region of the world.

现在,什么是课程?它是随着时间推移而重现的东西,还是在不同年份/季度中具有相同名称的类别分开的东西?课程可以包含不同形式/成绩/水平的学习者,还是这些学生的分区?课程是一组学生参加多个科目,还是特定科目分组?我熟悉两种类型的课程,可以称为表格课程和学术课程,但在您所在的地区可能会有所不同。

Using your class table:

使用您的班级表:

class (class_number PK, name, prerequisite, formation_time)

We need to link students to it. If class membership is an annual thing, we can add to the student relation above, e.g.

我们需要将学生与之联系起来。如果班级会员资格是年度会员,我们可以添加上述学生关系,例如:

student (person_id PK/FK, year, class_number FK)

Now, I just made up tables as I went along, but if you want to do this properly, you really should list/model your functional dependencies before you start making up tables. You could look into a formal modeling discipline like Object-Role Modeling, or at least write out simple logical relations in both directions:

现在,我只是编写了表格,但是如果你想要正确地做这个,你真的应该在开始编写表格之前列出/建模你的功能依赖。您可以查看像对象角色建模这样的正式建模规程,或者至少在两个方向上写出简单的逻辑关系:

a Student has one or more Parents
a Parent has one or more Students

a Class has a Year
a Year has zero or more Classes

a Student has a Class per Year

For non-binary relations, you don't need to write it out in every direction, but you do need to decide which combinations of attributes uniquely determine the others. For example, the combination of Student and Year uniquely determines the Class.

对于非二元关系,您不需要在每个方向上写出它,但您需要确定哪些属性组合唯一地确定其他方式。例如,Student和Year的组合唯一地确定了Class。

Anyway, that should give you a start.

无论如何,这应该给你一个开始。

#1


0  

First, I suggest you add a Person table to supertype Parent and Student, and move all the personal and contact information attributes to Person. You're sure to want to add additional information later, and having to duplicate everything for parents, students (and later, teachers and other school staff) gets to be a nuisance.

首先,我建议您添加一个Person表到父类和学生的超类型,并将所有个人和联系信息属性移动到Person。您肯定希望以后添加其他信息,并且不得不为父母,学生(以及后来的老师和其他学校员工)复制所有内容,这会让您感到非常麻烦。

person (person_id PK, last_name, first_name, sex, birthday, email, address, city, phone_number, cellphone_number)

Next, do you want to record biological parents or caregivers? In schools we normally care about caregivers and their relationship to the student. To record that, you could create a relationship type table:

接下来,您想记录亲生父母或看护人吗?在学校,我们通常关心照顾者及其与学生的关系。要记录它,您可以创建一个关系类型表:

relationship (relationship_id PK, description)

with entries for father, mother, aunt, grandfather, fostermother, etc. You can then record the relationship between 2 persons like so:

有父亲,母亲,阿姨,祖父,fostermother等条目你可以记录两个人之间的关系,如下所示:

parent (parent_id PK/FK, child_id PK/FK, relationship FK)

If you wanted to record biological parents, you could use:

如果你想记录亲生父母,你可以使用:

bioparents (child_id PK/FK, father_id FK, mother_id FK)

with father and mother ids nullable (or decompose into separate tables for father and mother) since we're unlikely to know both parents for all students.

由于我们不太可能为所有学生都认识父母,所以父亲和母亲的儿童可以*(或分解为父亲和母亲的单独表格)。

Finally, we get to the business at hand, students. Historical information and alumni are important in schools, so take care to model students over time, not just current students. You need to consider the time resolution for student registrations - are registrations annual, quarterly, or something else? For annual registrations, you could start with:

最后,我们到达了手头的企业,学生们。历史信息和校友在学校中很重要,因此要注意随着时间的推移对学生进行建模,而不仅仅是现在的学生。您需要考虑学生注册的时间分辨率 - 是年度,季度还是其他注册?对于年度注册,您可以从以下开始:

student (person_id PK/FK, year)

Now, what is a class? Is it something that recurs over time, or are classes with the same name in different years/quarters separate things? Can classes contain learners of different forms/grades/levels, or are they partitions of those? Is a class a grouping of students that attend multiple subjects, or a subject-specific grouping? I'm familiar with two types of classes, which could be called form classes and academic classes, but things may be different in your region of the world.

现在,什么是课程?它是随着时间推移而重现的东西,还是在不同年份/季度中具有相同名称的类别分开的东西?课程可以包含不同形式/成绩/水平的学习者,还是这些学生的分区?课程是一组学生参加多个科目,还是特定科目分组?我熟悉两种类型的课程,可以称为表格课程和学术课程,但在您所在的地区可能会有所不同。

Using your class table:

使用您的班级表:

class (class_number PK, name, prerequisite, formation_time)

We need to link students to it. If class membership is an annual thing, we can add to the student relation above, e.g.

我们需要将学生与之联系起来。如果班级会员资格是年度会员,我们可以添加上述学生关系,例如:

student (person_id PK/FK, year, class_number FK)

Now, I just made up tables as I went along, but if you want to do this properly, you really should list/model your functional dependencies before you start making up tables. You could look into a formal modeling discipline like Object-Role Modeling, or at least write out simple logical relations in both directions:

现在,我只是编写了表格,但是如果你想要正确地做这个,你真的应该在开始编写表格之前列出/建模你的功能依赖。您可以查看像对象角色建模这样的正式建模规程,或者至少在两个方向上写出简单的逻辑关系:

a Student has one or more Parents
a Parent has one or more Students

a Class has a Year
a Year has zero or more Classes

a Student has a Class per Year

For non-binary relations, you don't need to write it out in every direction, but you do need to decide which combinations of attributes uniquely determine the others. For example, the combination of Student and Year uniquely determines the Class.

对于非二元关系,您不需要在每个方向上写出它,但您需要确定哪些属性组合唯一地确定其他方式。例如,Student和Year的组合唯一地确定了Class。

Anyway, that should give you a start.

无论如何,这应该给你一个开始。