0

Say I have three entities(or tables): School, Student and Classroom. How do I ensure a Student belongs to a Classroom which belongs to the same School the Student belongs to? Considering a Student may not be part of any Classroom.

I'm facing that problem in many other ways. For example, when I add the entity Teacher. How can I guarantee at database level that a Teacher teaches on a Classroom of the same School the Teacher belongs to? And so on...

caeus
  • 3,084
  • 1
  • 22
  • 36
  • Can a teacher teach for a different school? Can a student take classes in more than one school? – Gordon Linoff Aug 31 '14 at 23:56
  • No, they can't, although they can change of school. But then the teacher can no longer teach in the previous school, and then student can no longer be in a classroom of the previous school. – caeus Sep 01 '14 at 00:39
  • Your problem is harder than it sounds. Don't try to enforce those relationships in the database, because the don't exist. A teacher might belong to one school one year and another the next year, but you've only allowed the teacher to have one school. – Gordon Linoff Sep 01 '14 at 01:26

0 Answers0