Normalize a table with tightly coupled data

白昼怎懂夜的黑 提交于 2019-12-23 04:52:18

问题


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)

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?


回答1:


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.



来源:https://stackoverflow.com/questions/39416557/normalize-a-table-with-tightly-coupled-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!