简体   繁体   English

我应该将数据库图中的哪些字段分成关系表?

[英]Which fields in my database diagram should I separate into relation tables?

I am struggling with the issue of trying to understand whether or not data should be separated into different tables or kept within the same, in a database logical diagram.我正在努力解决试图了解数据是否应该在数据库逻辑图中被分成不同的表或保存在同一个表中的问题。

My database is split into 3 parts: users (can be registered users who can post, view or like recipes; and admins who review published recipes and can accept or block users), recipes (which contains data like: dish name, category, dificulty, duration, servings, execution, view count and state) and ingredients.我的数据库分为 3 部分:用户(可以是可以发布、查看或点赞菜谱的注册用户;以及审查已发布菜谱并可以接受或阻止用户的管理员)、菜谱(其中包含以下数据:菜名、类别、难度、持续时间、份量、执行、查看次数和状态)和成分。

Recipes and ingredients have a many: many relationship so I have connected those two with a relation table called "Recipe_Ingredient".食谱和配料有很多:很多关系,所以我用一个名为“Recipe_Ingredient”的关系表将这两者联系起来。

Users to recipes has a 1: many relationship (one user can create many recipes, but each recipe can only be created by one user), but also a relation table connecting them because of the favorites section (ie one user can have many recipes as favorite, and each recipe can also be flagged as favorite by many users).用户与菜谱有 1: many 的关系(一个用户可以创建多个菜谱,但每个菜谱只能由一个用户创建),但由于收藏夹部分,还有一个连接它们的关系表(即一个用户可以拥有多个菜谱)最喜欢的,并且每个食谱也可以被许多用户标记为最喜欢的)。

But my actual problem is: I have separated from the table recipes a few fields (see image below for reference) such as Category, dificulty, and state.但我的实际问题是:我已经从表格配方中分离出几个字段(参见下图以供参考),例如类别、难度和 state。 Is this acceptable or are these fields better off kept within table recipes?这是可以接受的还是这些字段最好保留在表格食谱中?

Photo of what I have so far, for reference我目前的照片,供参考

Sorry for the long message.对不起,很长的消息。 Thank you so much for your help!非常感谢你的帮助!

I think the tables as you have them are mostly fine because as your data increases that's when you see the value of the design.我认为您拥有的表格大部分都很好,因为随着数据的增加,您就会看到设计的价值。 Here are a few ideas you can use for making these decisions if looking for optimizations:在寻找优化时,您可以使用以下一些想法来做出这些决定:

  1. Which tables are simply used for referential integrity with set values that will never change?哪些表仅用于具有永远不会更改的设置值的参照完整性? I would think state and difficulty.我认为 state 和难度。 The values in the recipe table like state should just show the state value so a lookup isn't needed.配方表中的值(如 state)应该只显示 state 值,因此不需要查找。 Sometimes these types of values that will not change end up in name-value pair tables(fieldname, fieldvalue, fieldtext) and the integrity handled on the front-end.有时,这些不会更改的值类型最终会出现在名称-值对表(字段名、字段值、字段文本)中,并且在前端处理完整性。 Of course this means that when I look at the recipe table, I can see the difficulty and state right away without going to look up the value elsewhere.当然这意味着当我查看配方表时,我可以立即看到难度和 state,而无需在其他地方查找值。
  2. If you had to move this into reporting or say analytics, do you have enough descriptors for an end-user to use?如果您必须将其转移到报告或分析中,您是否有足够的描述符供最终用户使用? This might be a good reason to keep the description for difficulty.这可能是保留困难描述的一个很好的理由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM