As you can see, Rooms table only has a column id and a name, and Schedule only has days and time. I want to ask if is it necessary to make an entity even it only has one or two columns?
If it’s possible, I want either Room or Schedule columns to move to Class, since the schedule only have date and time which are just limited data.
by using a foreign key in the schedule table, you ensure that only valid rooms are scheduled
you wouldn’t want an invalid room scheduled, right?
by the way, the FK relationship still would exist, and the value of having only valid rooms scheduled would be preserved, if, instead of a numeric id, the PK of the room table were the room name… then the FK in schedule would also be the room name
many database administrators will spit out their coffee when they read this, but data analysts all be like “so? that’s cool” – and furthermore, with the room name in schedule you don’t have to do the unnecessary join to translate the id
but the room table still needs to exist, even with just the one column
Okay, keep the table and make the Room name a primary key. Got it!
How about the Schedule columns? Should I just dissolve the table and move them to another table or should it remain and it will contain the FK room name?
Why do you join the “room” table directly with “class”, instead of with “schedule”?
At many schools, unis, etc. it is not uncommon that a “class” use different rooms through the week, if this is a functionality that needs to be added down the road. The current data model makes that difficult.
In short, why dont a “class” instead have multiple “schedule” records, and each “schedule” record would store the room the class is taught in. (I.e. one record for each different teaching session/class)
Be very very wary of the word always. Lots of time when you dig in you’ll find exceptions anyway. Better to find them up front then at the end. Changing a diagram is cheap, refactoring an entire database + code is not.
Always? Yes
Always? Yes
Always? Yes
Really, always? Well … there’s this one a day a year where…