如何为不同物品的库存构建数据库
我正在为不同项目的库存创建一个数据库。例如,我可能有汽车、发动机和化油器。
对于每种类型的项目,都有独特的属性,有些是唯一标识的(也称为“序列化”)项目,有些则不是。
例如,属性可以是:
汽车
- 序列号
- 颜色
- 门计数
- 传输类型
发动机
- 序列号
- 气缸计数
- 位移
<强>化油器(未序列化)
- 桶计数
- 制造商
当然,我需要能够确定我拥有的每种类型的物品有多少。我不想为每种类型创建一个表,因为当我开始携带变速器、轮胎、收音机、方向盘等时,物品类型会增加。
我见过的处理这种异构库存的一种方法是有一个 item
表,但也有一个 attribute
表。它看起来像这样:
**表:item **
- (键)itemType(链接到包含“汽车”、“引擎”等的 itemType 的表。
- (键)serialNumber
- (其他常见字段到所有 itemTypes)
**表:attribute **
- (key) attributeType(链接到 attributeTypes 表,例如“颜色”等)
- (key) itemType(链接到 中的 itemType项目)
- (key)serialNumber(链接到item中的serialNumber)
- attributeValue(如果attributeType是“颜色”,则可能是“红色”,“蓝色”等)
这带来的一个挑战是处理非虽然使用此结构很容易确定我有 35 个发动机,但我如何表示我有 52 个化油器?
当然,这不是唯一的方法。结构一您使用过什么数据库,或者您有什么其他想法?
谢谢您的帮助。
I'm creating a database for an inventory of unlike items. For example, I may have automobiles, engines, and carburetors.
For each type of item, there are unique attributes, and some are uniquely-identified (AKA "serialized") items, and some are not.
Attributes could be, for example:
Automobiles
- serialNumber
- color
- doorCount
- transmissionType
Engines
- serialNumber
- cylinderCount
- displacement
Carburetors (unserialized)
- barrelCount
- manufacturer
Of course, I need to be able to determine how many of each type of item I have. I don't want to create a table for each type, since the item type will increase as I begin to carry transmissions, tires, radios, steering wheels, etc.
One method I've seen to deal with such a heterogeneous inventory is to have an item
table, but to also have an attribute
table. It looks like this:
**Table: item **
- (key) itemType (linked to a table of itemTypes that include "automobile", "engine", etc.
- (key) serialNumber
- (other fields common to all itemTypes)
**Table: attribute **
- (key) attributeType (linked to a table of attributeTypes such as "color", etc.)
- (key) itemType (linked to itemType in item)
- (key) serialNumber (linked to serialNumber in item)
- attributeValue (if attributeType is "color", this might be "red", "blue", etc.)
One challenge this presents is dealing with non-serialized items. While it is easy with this structure to determine that I have 35 engines, how would I represent that I have 52 carburetors? I don't want to have to serialize them.
This, of course, is not the only way to structure a database for heterogeneous inventory. What have you used, or what other ideas do you have?
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试此表设置:
项目类型表:
项目表:
属性类型:
值表:
因此,如果您想存储引擎,则需要将类型“Engine”添加到类型表中,然后添加单个项目。然后,您可以添加“serial”和其他属性的值。
如果您想存储化油器,您可以添加一个名为化油器的类型,然后创建它的单个实例,然后为“数量”= 53 创建“值”条目。
希望这是有意义的
Try this table setup:
Item types table:
Items table:
Attribute_types:
Values table:
So, if you wanted to store an engine, you'd add the type "Engine" to types table, then add an individual item. Then, you could add values for "serial", and other properties.
If you wanted to store your carburetors, you could add a type called Carburetors, then make a single instance of it, and then make "value" entry for "quantity" = 53.
Hopefully this makes sense