Reputation: 3301
Suppose I have a table called "student" with a single column "name". And I want to store a second attribute called "group". "group" will be a value calculated from the name, and different names can be in the same group. So each name has a group and a group can have many names. This could be easily modeled in a normalised schema by creating a second table called "group" and adding a fk column to "student" that points to "group". However, suppose now that I can only calculate a student's group some time after they have registered. So I need to be able to enter a student without knowing their group. With this schema, I'll either have to use null fk's, or not add the student.
Apologies if I'm missing the obvious, I'm somewhat new to normalisation. What I have considered is using an associative table with a fk for group and a fk for student. This would allow me to enter students without knowing their groups and then linking them to their groups via the associative table at a later stage. But from what I've read on associative tables, you're meant to use them for deconstructing many-to-many relationships. And this is a one-to-many relationship. So I'm confused. Is there a standard way of normalising such a many-to-one relationship where the value can only be calculated later?
Upvotes: 0
Views: 23
Reputation: 1116
A pretty common way to solve this is just to have a "no group" record in the groups table. All students start off mapped to that record and then you update the foreign key when they are assigned to a group.
Upvotes: 1