in DB There are tables of universities (columns id_wuz, name_wuz), spr.Cities (id_gorod, name_gorod), spr.People (id_chelovek, name_chelovek, surname)

In the program, you need to make a table where users could enter the New Student, the city in which this student lives and in which university he will study: id_student, name_student, name_gorod, name_wuz.

I want to understand what is the most correct way to get such a table — do I need to link my directories or is this the shortest way?

  • Apparently, you need to read about foreign keys. - msi
  • If over time the same person can not study in different universities or move. Or maybe, but we are only interested in current information. That in the reference book of people we add the columns id_gorod and id_wuz. If you need to know when a person perezzhal and where he studied, then place the study and place of residence in separate tables like id_chlovek, id_gorod (wuz) well, and the intervals of dates with what number he lived / studied there - Mike

1 answer 1

If you need to specify in which city the student lives, you can make one table with foreign keys from the three directories.

I do not see all the conditions of the problem, but I would like to clarify that the student’s residence (in general) depends not on the student, but on the city in which the university is located. Also, universities can often differ only in the city of location (branches) . Therefore, my proposal is as follows: Create a table with foreign keys from the tables of the list of cities and the list of universities (in the diagram - the University) . Now build the dependency between the list of people and the table of universities using the Student table.

DB schema example