html - Set-up a Child Table that always has the same number of rows as the Parent table?
问题描述
I was wondering if there is any way to set-up the relationship between a Child and Parent table where the Child Table always has the same number of rows as the Parent Table.
An Example : The Parent table acts as a 'Master-list' or 'Dictionary' for ingredients used in a kitchen, within the table it would have multiple columns that store information on the ingredient such as - a unique ID, ingredient name, a supplier/brand, a unit of measurement, etc.
The Child table represents different locations where ingredients are stored, (Different Branches) - The Child Table would probably only have 2 columns being the ingredient's unique ID and Quantity. The child table needs to contain the same number of rows as Parent table. If a new entry is created in the Parent Table then the Child table should also have the new entry with Quantity = 0.
Alternative Solution : In the case that this isn't possible, What I currently have in mind in order to achieve this would be how I handle the forms, If a new entry into the Parent table is made it would also have code to insert the new entry into the existing Child tables, Though this would mean every-time there is a new location (new child table) I could also create a sort of form that checks if the Parent table and a specific Child table has the same number of Rows.
Thank you for your time and input.
解决方案
您计划为将存储成分数量的每个位置创建一个子表。这将产生多个表与成分表具有 1-1 关系的情况。此规范化不适用于您的用例。
考虑以下替代设计:
- 表
ingredients
存储成分主数据 - 表
locations
列出了不同的位置 - 表
ingredients_locations
存储每个位置的每种产品的数量:它有一个引用成分 id 的外键,还有一个指向位置 id 的外键
推荐阅读
- haskell - Haskell 镜头 - 棱镜组合
- python - RuntimeError:尺寸不匹配,m1:[672 x 224],m2:[672 x 224]
- java - 使用 java 的 AWS 电子邮件模板使用(批量电子邮件)
- python-3.x - Python 单击 JavaScript 中的按钮/链接
- vba - 从多个获胜者的 Excel 中的一行中选择一个得分获胜者
- react-native - React Native - 使用方括号获取正文
- hadoop - 色相在浏览器中执行任务和工作流运行有什么区别
- laravel - 如何在 Laravel Eloquent 中通过多个距离关系进行分组(通过急切加载的关系进行分组)
- python - 如何在旧的 Debian Linux 上安装最新的 pandas?
- android - 将文件保存在缓存中或设备内存中哪个更有效?安卓