库存控制的sql关系模型

qgzx9mmu  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(404)

我正在尝试创建一个mer图,对于具有以下逻辑的库存控制,我有10个相同型号的组件(10个acer 24监视器,具有相同的特性),唯一区别这些组件的是序列号,因此我有以下逻辑:

但我不知道这些关系是否正确,特别是对于库存零件,在组件实体中添加序列号并创建10个库存记录是否正确?

我很难为上述逻辑选择最佳路径。

xriantvc

xriantvc1#

在关系表示法中,每个关系都必须有一个主键,而在您的示例中: stock , component_has_component_category , user_has_components 别这样。
要解决此问题,请在每个关系的主键中添加这两个字段。 components 另一方面,关系有一个无用的领域 id ,可以用主键替换 component_id + serial_number ,如果用户具有组件(通过外键引用)关系,则也是如此 user_has_components 将有两个字段 component_id + serial_number 这是合乎逻辑的,因为用户有一个特定的组件示例。
假想关系 components_inventory 类似的,它有两个字段 component_id 以及 serial_number 同时是的主键和外键 components ,表示存在具有序列号的特定组件(在某种意义上 components_inventory 是的子集 components )
编辑:我对数据方面的看法:

component

| component_id | .. other stuff |
|            1 | ..             |
|            2 | ..             |

components (all existent components and serial numbers)

| component_id | serial_number |
|            1 |           101 |
|            1 |           102 |
|            1 |           103 |
|            1 |           104 |
|            2 |           201 |
|            2 |           202 |

user_has_component (refers to components)

| user_id | component_id | serial_number |
| mary    |            1 |           101 |
| john    |            1 |           104 |
| john    |            2 |           202 |

category_inventory (refers to components, some components we have, but not
users)

| component_id | serial_number | location           |
|            1 |           102 | warehouse New York |
|            1 |           103 | warehouse New York |
|            2 |           201 | warehouse Paris    |

相关问题