Create an SQL table with a different number of columns

I have two tables, say teacher and student. I want to build a third table called class.

There will be one column in the class table for the teacher of this class, but I want to see if this is an elegant way to represent students. My first thought is to say 30 columns .. student1, student2 and have quids for each of them that snap to a row in the student table.

But I ask you to see if there is a more preferable solution. The above solution seems awkward.

+3
source share
4 answers

If it were me, I would have a fourth table, called participants or similar, which connects students to the class, as this is the attitude of many to many. Which will contain the class identifier and student ID at least ..

+4
source

The class "table" is not a table, but the result of starting a stored procedure with data rotation.

And the data structure is as follows:

Student: Id, ...
Teacher: Id, ...
StudentClass: StudentId, ClassId, ...
Class: Id, TeacherId, ...
+3
source

SQL Server , . , PIVOT/ ,

+3

.

:

  • Student
  • TeacherStudent, , .

, . .

+2
source

Source: https://habr.com/ru/post/1765861/


All Articles