嘿,我遇到了以下问题:
Foods (is a Food (egg, milk, etc) OR a Recipe (bread, which is made out of eggs, flour, etc) ).
PK: foodId
FK: recipeId
Recipe (contains 1..many foods) Bread - eggs, flour, etc..
PK: recipeId
String: name
String: cooking
FK: foodId, foodId2, foodId3, ...
Meal (many foods = a meal) bread + marmelade + coffee
PK: mealId
String: name
FK: foodId, foodId2, foodId,3, ...
如何在数据库中创建这样的内容?
我不能使用相同的PK创建多个条目。
So example:
Recipe:
recipeId: 1
name: bread
cooking: mix all ingredients and then bake.
foodId: 1 (milk)
recipeId: 1
name: bread
cooking: mix all ingredients and then bake.
foodId: 2 (flour)
由于recipeId中的重复PK,这是不可能的。
我希望你能理解我的问题并提供答案。
答案 0 :(得分:1)
你可以做更多的事情:
Recipe
----
RecipeId
Name
PrepTime
CookTime
CuisineType
RecipeSteps
----
StepId
RecipeId
Instructions
RecipeStepIngredients
----
Id
StepId
FoodId
请注意,这远非完美,但至少可以让你开始。
基本上:
一顿饭可以有很多食谱
食谱可以有很多步骤
单步可以有许多成分(由几种食品组成)