J
Jonathan Wood
I'm trying to decide the best table structure for a database and was hoping
some folks with more experience might have some suggestions.
I have the following tables: [Users], [Menus], [MenuDetails], and [Foods].
These tables define menu plans for each user.
The relationships are as follows:
[Foods]<--[MenuDetails]-->[Menus]-->[Users]
(There can be any number of menus per user, any number of menu details per
menu, and any number of menu details referencing the same food.)
This seems straight forward but the problem is that I now need to allow
Users to create their own foods, which can be used in their menus. I hate to
make the data structure more complex.
One thought is to store user foods in the main foods table. I could add a
UserID field to the foods table and keep it NULL for foods that are not
specific to a particular user.
I'm not sure how clear that is. I'm trying to figure out how much sense this
approach makes, particularly using NULL for UserIDs when a food is not
associated with a user. Also, it would be nice to keep the main food table
separate in case some bad code deletes all the foods during testing. But
adding another table for user foods just seems like it would make the query
a nightmare.
It'd be great if anyone could speak to this!
some folks with more experience might have some suggestions.
I have the following tables: [Users], [Menus], [MenuDetails], and [Foods].
These tables define menu plans for each user.
The relationships are as follows:
[Foods]<--[MenuDetails]-->[Menus]-->[Users]
(There can be any number of menus per user, any number of menu details per
menu, and any number of menu details referencing the same food.)
This seems straight forward but the problem is that I now need to allow
Users to create their own foods, which can be used in their menus. I hate to
make the data structure more complex.
One thought is to store user foods in the main foods table. I could add a
UserID field to the foods table and keep it NULL for foods that are not
specific to a particular user.
I'm not sure how clear that is. I'm trying to figure out how much sense this
approach makes, particularly using NULL for UserIDs when a food is not
associated with a user. Also, it would be nice to keep the main food table
separate in case some bad code deletes all the foods during testing. But
adding another table for user foods just seems like it would make the query
a nightmare.
It'd be great if anyone could speak to this!