Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7830667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:20:39+00:00 2026-06-02T11:20:39+00:00

As part of database design task for a high school, I am kind of

  • 0

As part of database design task for a high school, I am kind of stuck with classes table. The tables created so far are:

Students
--------------
Id
name

Grades (grade 1,2,....9,10)
------------------
id    
description    
term

Subjects (science,maths...)
-------------------
id
name

grade_subject (subjects tought in grades)
----------------
id
grade_id
subject_id

teacher
---------------------
id
name

teacher_subject (teachers who are assigned to teach subjects in particular grade)
---------------------
id
teacher_id
grade_subject_id

I am not confident about table design of teacher_subject table. This table makes use of id of grade_subject_id which might (not) be a good design. Should this table have two FKs , one grade_id and subject_id?

I also need further to store number of classes conducted on particular subject and grade by particular assigned teacher.

Would this table fit in this case:

Class (stores daily teaching schedule)
-----------------------------------
id
*teacher_id
grade_id
subject_id*

*or only teacher_subject_id from teacher_subject table*

date
start_time
end_time
status ( conducted/cancelled/postponed)+

And lastly, a table to store information about who attended the class

attandants
--------------------
student_id
class_id

Any suggestions would greatly be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T11:20:48+00:00Added an answer on June 2, 2026 at 11:20 am

    Data modelling is the art of representing the real world in a relationship diagram. Your mode is correct but is it true?

    Consider, what is a CLASS? It’s a TEACHER, a SUBJECT and a GRADE. Those are your relationships. In addition you want to enforce the rules that the SUBJECT is appropriate for that GRADE and that the TEACHER can teach that SUBJECT in that GRADE.

    I think your problem lies in the use of surrogate keys in the intersection tables. These are the tables which represent your many-to-many relationships: teacher_subject, grade_subject. These are synthetic tables anyway, and they only consist of keys anyway. Hence a composite primary key will suffice.

    Surrogate primary keys have no meaning, so we need to define a unique constraint on grade_subject(subject_id, grade_id) to ensure we don’t have two records for (‘PHYSICS’, ‘YEAR 2’). Given that grade_subject is an intersection table with no other columns adding a surrogate key is pointless. The value of surrogate keys is to minimise the impact of a business key changing. But grade_subject doesn’t have a business key, just two surrogate keys, subject_id and grade_id.

    This has an advantage when it comes to defining referential integrity.

    So I would approach your problem this way:

    grade_subject 
    ----------------
    grade_id
    subject_id
    primary key (grade_id, subject_id)
    foreign key (grade_id) reference grade (grade_id) 
    foreign key (subject_id) reference subject (subject_id) 
    
    teacher_subject 
    ---------------------
    teacher_id
    grade_id
    subject_id
    primary key (teacher_id,grade_id, subject_id)
    foreign key (grade_id) reference grade (grade_id) 
    foreign key (subject_id) reference subject (subject_id) 
    foreign key (teacher_id) reference teacher (teacher_id) 
    foreign key (grade_id,subject_id) reference grade_subject (grade_id,subject_id) 
    
    Class 
    -----------------------------------
    id
    teacher_id
    grade_id
    subject_id
    primary key (id)
    foreign key (grade_id) reference grade (grade_id) 
    foreign key (subject_id) reference subject (subject_id) 
    foreign key (teacher_id) reference teacher (teacher_id) 
    foreign key (grade_id,subject_id) reference grade_subject (grade_id,subject_id)
    foreign key (teacher_id,grade_id,subject_id) reference teacher_subject (teacher_id,grade_id,subject_id) 
    

    This may look like a pile up of foreign keys, and I can envisage some arguments at the review stage. (I include the foreign key on grade_subject so I’ve got something to concede which I don’t care about that much and so could concede).

    But I don’t like having significant data relationships such as CLASS_SUBJECT obfuscated by being enforced through a subsidiary relationship such as TEACHER_SUBJECT. I don’t want to have to join to TEACHER_SUBJECT and SUBJECT_GRADE in order to join CLASS to SUBJECT.

    Now, why do I choose to include referential integrity constraints to the single parent tables and the intersection table when the latter indirectly enforces the former? Because it makes the relationships clearer in the model. I stress in the model, because in the physical database I might choose to omit the single table foreign keys, or disable them, and trust in the relational integrity of the intersection table.


    Something about a triple column composite bugs me, and I think it’s this: it’s not sufficiently normalised. You may have a special case but the more general model would be two rules, TEACHER_SUBJECT and TEACHER_GRADE. That would look like this

    teacher_subject 
    ---------------------
    teacher_id
    subject_id
    primary key (teacher_id, subject_id)
    foreign key (subject_id) reference subject (subject_id) 
    foreign keye (teacher_id) reference teacher (teacher_id) 
    
    teacher_grade 
    ---------------------
    teacher_id
    grade_id
    primary key (teacher_id,grade_id)
    foreign key (grade_id) reference grade (grade_id) 
    foreign key (teacher_id) reference teacher (teacher_id) 
    
    Class 
    -----------------------------------
    id
    teacher_id
    grade_id
    subject_id
    primary key (id)
    foreign key (grade_id) reference grade (grade_id) 
    foreign key (subject_id) reference subject (subject_id) 
    foreign key (teacher_id) reference teacher (teacher_id) 
    foreign key (grade_id,subject_id) reference grade_subject (grade_id,subject_id)
    foreign key (teacher_id,subject_id) reference teacher_subject (teacher_id,subject_id) 
    foreign key (teacher_id,grade_id) reference teacher_grade (teacher_id,grade_id) 
    

    Of course, if you still wanted to enforce a rule that Mr Drury could only teach Maths to fourth formers and Physics to sixth formers you would need a TEACHER_SUBJECT_GRADE table.


    One thing your data model doesn’t address is the problem of scheduling. School timetables have to mesh, so Classes need to fit into a pre-determined grid. You probably need to define the timetable’s slots as a separate table and link CLASS to that. Classes also need Classrooms. That’s another table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a claims database with the above schema so far. Three three-part key
I'm developing a high-volume web application, where part of it is a MySQL database
The way a part of my database is designed I have three tables: Partners
I'm trying to decide on a database design. More specifically, this is a sub-part
The party model is a pattern for relational database design. At least part of
My question relates to the best practices design of tables in a database for
I'm looking for help with part of a database design. I have to Model
Are there any examples of database design for public transport time-tables ? Or any
I am making a database of students in one school.Here is what I have
As part of our database revision control (and auto-installation) procedures we need to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.