-4

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:

Click to see the image

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
stack
  • 33
  • 1
  • 2
  • 9

1 Answers1

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

White Feather
  • 2,733
  • 1
  • 15
  • 21
  • How many exams has a course? How many semester has a course? But your course table has many courses... should not it be a totally different set up with corse_id |course_name | semester | exam... and so on. The problem is too vague to help you in design the DB. You should describe what you are trying to achieve.... – White Feather Mar 19 '16 at 09:11
  • Express the problem. How can be designed an answer if the problem is not set? What are you trying to achieve? Describe the real life contest before talking of tables... – White Feather Mar 19 '16 at 09:49
  • Courses can be held in 1st, 2nd semester or both maintaining the same id and title : For this the same courses are taken in the 2 semesters., There are up to 3 exams per course per semester: For each course in each semester we make a test. The exam is done at the last year. The confusion is now in the table exams id_student | id_course | semester | exam | grade for the columns semester exam grade it impossible to know if the grade belongs to exam or the semester ? How to fix it ? – stack Mar 19 '16 at 11:18
  • Sorry buddy for to answer so later. Now i see my problem is near solved. Thank you very much for taking your time. I have a last question, how do you randomly get these values? 2701 | K409 | 2015 | 1 | 1 | NULL | 4 – stack Mar 20 '16 at 11:23
  • I just set them manually. You can generate random numbers with this: http://stackoverflow.com/questions/14798640/creating-a-random-number-using-mysql, or random string with this: http://www.sixarm.com/about/mysql-create-random-data-text-strings.html – White Feather Mar 20 '16 at 17:20