使用紧耦合数据规范化表

编程入门 行业动态 更新时间:2024-10-28 10:34:08
本文介绍了使用紧耦合数据规范化表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前有一个表格,用于存储用于创建项目的材料

I currently have a table that stores the materials used to create an item

Item (material1, material2, material3)

最近添加了另一种材料.但是,我想对该表进行规范化,以便将来添加新材料时不需要将新列添加到数据库中.我把材料提取到下面的连接表中

Another material has recently been added. However, I want to normalize this table so that in the future, adding a new material won't need a new column to be added to the database. I extracted the materials into the following junction table

ItemJuncMaterial (id, itemId, materialid)

然而,问题在于材料的顺序很重要.所以这个连接表不允许我根据材料运行这个查询来获取项目

However, the catch is that the order of the materials matter. So this junction table won't allow me to run this query based on materials to get the item

select itemid from ItemJunMaterial where materialid in (1,2,3)

这可以返回使用 2,3,1 甚至可以使用两种材料 1,2 的项目.有没有更好的方法来拆分这个表来规范化它并使其更具动态性?

This can return items that use 2,3,1 or could even use two materials 1,2. Is there a better way to split up this table to normalize it and make it more dynamic?

推荐答案

您应该考虑物料清单"(BOM) 模式(请参阅 此处 或此处).BOM 的交集可以包括有关组成的额外信息,例如每个组件的数量.您可以轻松地在该交集中包含组件的顺序或优先级.

You should consider a "bill of materials" (BOM) pattern (see here or here). The intersection of a BOM can include extra information about the composition, such as quantity of each component. You could easily include the sequence or priority of the component in that intersection just as easily.

更多推荐

使用紧耦合数据规范化表

本文发布于:2023-11-22 09:17:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616846.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!