database 存储食物食谱的数据库设计

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3225536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 07:47:10  来源:igfitidea点击:

Database design for storing food recipes

databasedatabase-design

提问by Cass

I want to make a database of recipes that I like, but I'm having trouble designing it. I want to have at least two tables:

我想制作一个我喜欢的食谱数据库,但我在设计它时遇到了麻烦。我想要至少有两个表:

  1. Recipe table (Has description, ingredients, directions, etc...)
  2. Ingredients table (ingredient type, other attributes, etc...)
  1. 配方表(有说明、成分、说明等...)
  2. 配料表(配料类型、其他属性等...)

What would be a way to associate a the two tables together? Would I need a third table that would store the several relationships from a recipe to multiple ingredients?

将这两个表关联在一起的方法是什么?我是否需要第三张表来存储从配方到多种成分的几种关系?

As you can probably tell, I'm relatively new to this stuff, just trying to figure out the right way to do it on the first try.

正如您可能会说的那样,我对这些东西比较陌生,只是试图在第一次尝试时找出正确的方法。

Thanks!

谢谢!

采纳答案by Swift

Here is a link to a pretty advanced one:

这是一个非常高级的链接:

http://www.databaseanswers.org/data_models/recipes/index.htm

http://www.databaseanswers.org/data_models/recipes/index.htm

but if you really want to code it yourself I would go with a third relational table.

但如果你真的想自己编码,我会使用第三个关系表。

cheers, Mike

干杯,迈克

回答by Chris Diver

Does one recipe have many ingredients or many recipe's have many ingredients

一个食谱有很多成分还是很多食谱有很多成分

I'd expect it will be the latter to allow you to find recipe's by ingredient.

我希望后者可以让您按成分找到食谱。

So you will need an intermediate table to break the many to many relationship into two one to many relationships.

因此,您将需要一个中间表来将多对多关系分解为两个一对多关系。

Recipe(RecipeID, etc...) 
Ingredients(IngredientID, etc....)
RecipeIngredients(RecipeID, IngredientID, etc..)

Then in RecipeIngredientsI would put information such as quantities of that ingredient for that recipe.

然后RecipeIngredients我会在其中输入信息,例如该食谱的该成分的数量。

回答by pascal

You could consider something like a folder of text files, with a full-text index of some sort.

您可以考虑类似于文本文件文件夹的内容,其中包含某种全文索引。

Or a table like Recipes(ID, LikeRatio, Description as text). Again with a full-text search.

或者像 Recipes(ID, LikeRatio, Description as text) 这样的表格。再次进行全文搜索。

Theorically you could use a normalized model like the one @Mike suggested. But looking at actual recipes, it needs to be more flexible. For example in this model, there's no evidence of the use at some step of the outcome of a previous step.

从理论上讲,您可以使用像@Mike 建议的那样的规范化模型。但看看实际的食谱,它需要更加灵活。例如,在这个模型中,没有证据表明在某个步骤中使用了上一步的结果。