I donβt quite understand why you need what you described, but I would look at the model as follows ...
Do you have students
- These are different objects, not components of other objects - They have their own properties; name, date of birth, etc.
You have classes
- This is a group of students
- Each academic year of the same "class" different students participate in it
- They also have their own properties; class, subclass, etc.
You have an additional property in your model that I would not normally use - If the class has 20 students, each of them is identified with a secondary identifier from 1 to 20
This will give me the following measurement tables
Student Class Grade SubGrade ----------------------- ------------------------ ----------------- ----------------- id INT PK id INT PK id INT PK id INT PK first_name VARCHAR(45) name VARCHAR(45) name VARCHAR(45) name VARCHAR(45) last_name VARCHAR(45) grade_id INT FK desc VARCHAR(45) desc VARCHAR(45) etc, etc subgrade_id INT FK etc, etc etc, etc
The Class table would have a unique restriction on (grade_id, subgrade_id) , so only one class could be 7b .
Then you need to associate students with their classes using a fact table ...
Class_Membership ----------------------- id INT PK student_id INT FK class_id INT FK academic_year INT
If a student should be in only one class in any school year, you must set a unique limit on (student_id, academic_year) .
Alternatively, you can get the school year in the Class table. This would mean that you would repeat the same class for each year, but in some years, class 7g might not exist (for example, fewer students study this year).
Equally, you may have students who go from 7b to 7c in the middle of the year. In this case, the Class_Membership table may have a start_date field and, possibly, an end_date field.
However, none of this directly creates the id_class field (1-20 for a class with 20 students). Personally, I would not have such a field, the id field from the Class_Membership table can serve most of the same functions and, possibly, additional functions. However, if necessary, you can simply add it to the Class_Membership table ...
Class_Membership ----------------------- id INT PK student_id INT FK class_id INT FK academic_year INT class_member_id INT
Then you may also have a unique restriction on (academic_year, class_id, class_member_id) .
There is quite a bit of flexibility here, depending on your specific model of the real world and your specific needs. But hopefully this example is a good start for you; Size tables listing entities and a fact table (or tables) linking these entities together and / or further description of objects.