Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not totally clear on why you want what you have described, but I would look at the model in the following way...</p> <p>You have Students<br> - They are distinct entities, not a composite of other entities<br> - They have their own properties; name, date of birth, etc </p> <p>You have classes<br> - These are groups of students<br> - Each accademic year the same "class" has different students in it<br> - They also have their own properties; grade, sub-grade, etc </p> <p>You have an extra property in your model that I would not normally use<br> - If a class has 20 students, each of them is identified with a secondary id from 1 to 20 </p> <p><br/></p> <p>This would give <em>me</em> the following Dimension tables</p> <pre><code>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 </code></pre> <p>The <code>Class</code> table would have a unique constraint on <code>(grade_id, subgrade_id)</code> so that only one class could ever be <code>7b</code>.</p> <p>Then you need to relate the students to their classes using a fact table...</p> <pre><code>Class_Membership ----------------------- id INT PK student_id INT FK class_id INT FK academic_year INT </code></pre> <p>If a student should only ever be in one class in any academic year, you would put a unique constraint on <code>(student_id, academic_year)</code>.</p> <p>Alternatively, you could have the academic year in the <code>Class</code> table. This would mean that you would have the same class repeated for every year, but that in some years class <code>7g</code> may not exist <em>(as there are less students that year, for example)</em>.</p> <p>Equally, you could have students who move from <code>7b</code> to <code>7c</code> mid-year. In which case the <code>Class_Membership</code> table could have a <code>start_date</code> field and possibly an <code>end_date</code> field.</p> <p><br/></p> <p>None of that, however, directly creates the <code>id_class</code> field <em>(1-20 for a class with 20 students)</em>. Personally I would not have such a field, the <code>id</code> field from the <code>Class_Membership</code> table can serve most of the same functionality, and probably additional functionality. Where it <em>is</em> necessary, however, you could simply add it to the <code>Class_Membership</code> table...</p> <pre><code>Class_Membership ----------------------- id INT PK student_id INT FK class_id INT FK academic_year INT class_member_id INT </code></pre> <p>Then you could also have a unique constraint on <code>(academic_year, class_id, class_member_id)</code>.</p> <p><br/></p> <p>There is quite a lot of flexibility here, depending on your exact real-world-model and your particular needs. But hopefully this example is a good start for you; Dimension tables listing Entities, and a Fact table (or tables) relating these entities together and/or further describing the Entities.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload