0

I'm working on a project for a database that contains, in the best way, the nutritional values ​​of foods. They are divided according to type of food, eg Breakfast, Lunch, Dinner. For portions of the food, for example ml, g, etc. oz. That have the name of each food and all of its nutritional values.

Like this.

Food
==========
ID
NAME

NUTRITIONAL_FACTS
==========
ID
NUTRITIONAL_FACTS_FOOD_ID
KCAL
FAT
SUGAR
PROTEINS

PORTIONS
==========
ID
PORTION
FOOD_ID

TYPE_FOOD
=========
ID
TYPE_FOOD
FOOD_ID

Could someone tell me which solution would be most appropriate for the design of this database?

4
  • What "type of food" is, say, a slice of toast?
    – AakashM
    Sep 11, 2014 at 14:53
  • 2
    Is this a homework question?
    – datagod
    Sep 11, 2014 at 15:02
  • As a former moderator for cooking.SE, with a degree in library science ... I'd question your category of 'type of food' having values of 'breakfast', 'lunch' and 'dinner'. Those would be meals, but even then, a given dish may served at different meals depending on the culture (eg, pancakes), and there are a ton of foods that on their own isn't necessarily a meal (eg, an apple ... is it an ingredient? a snack? part of a fruit and cheese plate after dinner?)
    – Joe
    Sep 11, 2014 at 18:04
  • @Joe Nice to meet you Joe. Your questions are interesting. I think it's fair to call the table "food types"> "types of meals." For the problem of the cultures I prefer to create a database Apart, since the data will be large, as long as you do not have a better idea. For foods that are not necessarily meals do not make a difference since each person can eat as an apple or milk at dinnerwill be a choice of the user.
    – Sergeyweb
    Sep 11, 2014 at 18:59

1 Answer 1

1

Some thoughts on the design of this database:

  • For portions, is there only ever one per food? If so it belongs in the food table.
  • Similarly, with the nutritional facts, only per food? If so, probably just in the food table. If there are multiple portions, it would seem like the nutritional facts are based on the portion.
  • And for types, only one per food, or can a food be listed as both a lunch and dinner food? If you have multiple portions, you might have a lunch portion and a dinner portion, and as such the type would be as part of the portions.

So, if only one portion, one nutritional fact, and one type per table, I'd just have it all in the one Food table, potentially with indexes on fields the user may search on.


(edited after more information)

Based on there being multiple portions per food, and the nutritional facts being dependent on the portion, it would make sense to put the nutritional facts in the portion table. It would seem like your Food and Type tables can remain as you originally posted, so the Portions table looks something like this:

PORTIONS
==========
ID
PORTION
FOOD_ID
KCAL
FAT
SUGAR
PROTEINS
3
  • The portions can be one or more for each food, for example: A food like burgers, can have a portions like, grams, 1 sandwich, 1 slice etc. The nutritional values are different for each portion of course. A food may be both for lunch and dinner or other, such as salad. I do not need to have a portion for each type of food. About this information as it would be best to proceed? Thanks so much for the help you're giving me.
    – Sergeyweb
    Sep 11, 2014 at 16:53
  • Why is better nutritional facts in the portion table? For making query or logic? Why not the same for type of food (or type of meals)?
    – Sergeyweb
    Sep 11, 2014 at 19:01
  • Because the nutritional facts are directly related to the portion, it makes sense to keep them together. For the food type, for instance in your salad example, the portion and nutritional facts don't change for a given portion size, whether it is a lunch or dinner, so keep it separate.
    – DerekCate
    Sep 15, 2014 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.