My database holds schools, divisions, and courses. A school may or may not have divisions, and a courses is related to a school, and may or may not be related to a division (the school may not have divisions, or the course may be cross-divisioned)
My tables are currently set up as follows:
school:
ID | name
--------------------
harvard | Harvard University
mit | MIT
ucla | UCLA
division (id+school=unique)
ID | school (FK) | name
------------------------------------------
eng | harvard | School of Engineering
arc | harvard | School of Architecture
eng | UCLA | UCLA Engineering
course:
ID | school (FK) | division | name
-------------------------------------------------
1 | harvard | eng | Intro to Engineering
2 | harvard | arc | Intro to Architecture
3 | harvard | | Statistics
4 | mit | | Math
My concerns with this:
- There is no validation to make sure the divisions in
courseexists and is related to the school. - division is not actually a fk
- It takes two queries to get the school and division
Is there a better way of doing this? I want to be able to:
- Query all "harvard" courses
- Query all "harvard engineering" courses
- Query all "harvard engineering and harvard general" courses