您对mysql workbench中的表有何看法?链接表?

时间:2022-07-07 12:34:26

I'm making a small program in Java and I want if I put the name and the born date in a textfield it will fetch the result of the student in semester and the exam. Below the table I made and I have a problem to link these table:

我正在用Java创建一个小程序,我想如果我把名字和出生日期放在文本字段中,它将在学期和考试中获取学生的结果。在我的表下面,我有一个问题链接这些表:

您对mysql workbench中的表有何看法?链接表?

1 个解决方案

#1


0  

Your DB structure has no link possibility.

您的数据库结构没有链接可能性。

No table has a key that can link it to another table.

没有表具有可以将其链接到另一个表的键。

You have to identify the one-to-many and many-to-many associations and express them with the appropriate method in term of keys.

您必须识别一对多和多对多关联,并使用适当的方法在密钥方面表达它们。

Example:

I suppose that table student and table course have a many-to-many relation, that you should express with a table like:

我认为表学生和表课程有多对多的关系,你应该用表格来表达:

ideleve | idcourse

You have to work out all these relations on your structure to design any query.

您必须在结构上计算出所有这些关系才能设计任何查询。

Following your comments I update the answer. In reality I should vot to close this question, as it is too broad and not over coding.

根据您的意见,我更新答案。实际上,我应该投票结束这个问题,因为它太宽泛而且不会过度编码。

EXAMPLE OF PROBLEM SETTING:

问题设置示例:

Each student is identified by:
id | name | surname | born_date

Each course is identified by
id | course_title

Students can enroll in multiple courses

Courses can be held in 1st, 2nd semester or both maintaining the same id and title

There are up to 3 exams per course per semester

Notes of each exam can go from 1 to 5 with 1 being the lowest

Students have to take all the exams, if they do not take an exam their vote is considered 0 for that exam

This would led to a possible:

这将导致一种可能:

DB STRUCTURE

table students
id_student | name | surname

table courses
id_course | course_title

table exams
id_student | id_course | semester | exam | grade

with the implicit relations you can understand from columns names.

您可以从列名称中理解隐式关系。

Then you can start with coding...

那么你可以从编码开始......

But here I am making a whole lot of assumptions on students, courses, exams and gardes and their relationships!

但在这里,我对学生,课程,考试和花园以及他们的人际关系做了很多假设!

To design a DB an analysis of entities and relationships is needed.

要设计数据库,需要对实体和关系进行分析。

the program you are trying to make is surely very simple as you say, also this analysis is not complex, but has to be done, and none can do that for you.

正如你所说,你想要制作的程序肯定非常简单,这种分析并不复杂,但必须要完成,没有人可以为你做到这一点。

Following your last comment that finally clarify the problem you can do:

根据您最后的评论,最终澄清您可以执行的问题:

DB STRUCTURE

table students
id_student | name | surname | birthdate

table courses
id_course | course_title | year | semester

table exams
id_student | id_course | year | semester | test | exam | grade

example of table exams could be:

表格考试的例子可以是:

id_student | id_course | year | semester | test | exam | grade
--------------------------------------------------------------
  2701     |  K409     | 2015 |    1     |   1  | NULL |  4
  2701     |  K409     | 2015 |    1     |   2  | NULL |  4
  2701     |  K409     | 2015 |    1     |   3  | NULL |  4
  2701     |  K409     | 2015 |    0     | NULL | NULL |  3
  2701     |  K405     | 2015 |    1     |   1  | NULL |  4
  2701     |  K405     | 2015 |    1     |   2  | NULL |  4
  2701     |  K405     | 2015 |    1     |   3  | NULL |  4
  2705     |  K405     | 2015 |    0     | NULL | NULL |  3
  2705     |  K409     | 2015 |    2     |   1  | NULL |  4
  2705     |  K409     | 2015 |    2     |   2  | NULL |  4
  2705     |  K409     | 2015 |    2     |   3  | NULL |  4
  2705     |  K409     | 2015 |    0     | NULL | NULL |  3
  2705     |  K407     | 2015 |    2     |   1  | NULL |  4
  2705     |  K407     | 2015 |    2     |   2  | NULL |  4
  2705     |  K407     | 2015 |    2     |   3  | NULL |  4
  2705     |  K407     | 2015 |    0     | NULL | NULL |  3

You can link courses to exams/test using multi-columns key:

您可以使用多列键将课程链接到考试/测试:

 id_course-year-semester

link student to exams/test with:

将学生与考试联系起来/考试:

 id_student

link student to courses through the exams/test table where you have:

通过考试/测试表将学生链接到课程:

id_student | id_course-year-semester

which means that when a student register for a course a record like this will be in the exams/test table:

这意味着当学生注册课程时,这样的记录将出现在考试/测试表中:

id_student | id_course | year | semester | test | exam | grade
--------------------------------------------------------------
  2701     |  K409     | 2015 |    1     | NULL | NULL |  NULL

Regards

#1


0  

Your DB structure has no link possibility.

您的数据库结构没有链接可能性。

No table has a key that can link it to another table.

没有表具有可以将其链接到另一个表的键。

You have to identify the one-to-many and many-to-many associations and express them with the appropriate method in term of keys.

您必须识别一对多和多对多关联,并使用适当的方法在密钥方面表达它们。

Example:

I suppose that table student and table course have a many-to-many relation, that you should express with a table like:

我认为表学生和表课程有多对多的关系,你应该用表格来表达:

ideleve | idcourse

You have to work out all these relations on your structure to design any query.

您必须在结构上计算出所有这些关系才能设计任何查询。

Following your comments I update the answer. In reality I should vot to close this question, as it is too broad and not over coding.

根据您的意见,我更新答案。实际上,我应该投票结束这个问题,因为它太宽泛而且不会过度编码。

EXAMPLE OF PROBLEM SETTING:

问题设置示例:

Each student is identified by:
id | name | surname | born_date

Each course is identified by
id | course_title

Students can enroll in multiple courses

Courses can be held in 1st, 2nd semester or both maintaining the same id and title

There are up to 3 exams per course per semester

Notes of each exam can go from 1 to 5 with 1 being the lowest

Students have to take all the exams, if they do not take an exam their vote is considered 0 for that exam

This would led to a possible:

这将导致一种可能:

DB STRUCTURE

table students
id_student | name | surname

table courses
id_course | course_title

table exams
id_student | id_course | semester | exam | grade

with the implicit relations you can understand from columns names.

您可以从列名称中理解隐式关系。

Then you can start with coding...

那么你可以从编码开始......

But here I am making a whole lot of assumptions on students, courses, exams and gardes and their relationships!

但在这里,我对学生,课程,考试和花园以及他们的人际关系做了很多假设!

To design a DB an analysis of entities and relationships is needed.

要设计数据库,需要对实体和关系进行分析。

the program you are trying to make is surely very simple as you say, also this analysis is not complex, but has to be done, and none can do that for you.

正如你所说,你想要制作的程序肯定非常简单,这种分析并不复杂,但必须要完成,没有人可以为你做到这一点。

Following your last comment that finally clarify the problem you can do:

根据您最后的评论,最终澄清您可以执行的问题:

DB STRUCTURE

table students
id_student | name | surname | birthdate

table courses
id_course | course_title | year | semester

table exams
id_student | id_course | year | semester | test | exam | grade

example of table exams could be:

表格考试的例子可以是:

id_student | id_course | year | semester | test | exam | grade
--------------------------------------------------------------
  2701     |  K409     | 2015 |    1     |   1  | NULL |  4
  2701     |  K409     | 2015 |    1     |   2  | NULL |  4
  2701     |  K409     | 2015 |    1     |   3  | NULL |  4
  2701     |  K409     | 2015 |    0     | NULL | NULL |  3
  2701     |  K405     | 2015 |    1     |   1  | NULL |  4
  2701     |  K405     | 2015 |    1     |   2  | NULL |  4
  2701     |  K405     | 2015 |    1     |   3  | NULL |  4
  2705     |  K405     | 2015 |    0     | NULL | NULL |  3
  2705     |  K409     | 2015 |    2     |   1  | NULL |  4
  2705     |  K409     | 2015 |    2     |   2  | NULL |  4
  2705     |  K409     | 2015 |    2     |   3  | NULL |  4
  2705     |  K409     | 2015 |    0     | NULL | NULL |  3
  2705     |  K407     | 2015 |    2     |   1  | NULL |  4
  2705     |  K407     | 2015 |    2     |   2  | NULL |  4
  2705     |  K407     | 2015 |    2     |   3  | NULL |  4
  2705     |  K407     | 2015 |    0     | NULL | NULL |  3

You can link courses to exams/test using multi-columns key:

您可以使用多列键将课程链接到考试/测试:

 id_course-year-semester

link student to exams/test with:

将学生与考试联系起来/考试:

 id_student

link student to courses through the exams/test table where you have:

通过考试/测试表将学生链接到课程:

id_student | id_course-year-semester

which means that when a student register for a course a record like this will be in the exams/test table:

这意味着当学生注册课程时,这样的记录将出现在考试/测试表中:

id_student | id_course | year | semester | test | exam | grade
--------------------------------------------------------------
  2701     |  K409     | 2015 |    1     | NULL | NULL |  NULL

Regards