【问题标题】:Asset Inventory Database Design资产库存数据库设计
【发布时间】:2017-02-20 01:56:08
【问题描述】:

我在一家 IT 商店工作,正在尝试创建一个数据库来跟踪我们的硬件库存。要点是,带条形码的资产只能位于一个位置,可以是桌子、架子或某种存储设备(架子、托盘等)。

我本来就有这样的东西。

Table Asset(barcode);
Table Rack(rack_id, rackName);
Table Desk(desk_id, deskName);
Table Storage(storage_id, StorageName);

对于每个“位置”表(机架、办公桌、存储),我都有一个表来跟踪资产的放置位置:

Table Desk_Item (desk_item_id, desk_id, barcode);
Table Rack_Item (rack_item_id, rack_id, barcode);
Table Storage_Item (storage_item_id, storage_id, barcode);

但我不喜欢使用三个单独的表来跟踪资产的想法。所以我想我应该做一个位置表

Table Location(location_id, barcode);
Table Rack(rack_id, rackName, location_id);
Table Desk(desk_id, deskName, location_id);
Table Storage(storage_id, StorageName, location_id);
Table Asset(barcode);

所以现在位置表会跟踪资产的位置。但让我感到奇怪的是,如果我查询 Location 表,我必须检查 Rack、Desk 和 Storage。这是设计这个的正确方法吗?感谢任何想法或建议。

【问题讨论】:

  • 为什么需要位置表?资产总是在某处。将其存储在 Asset 表中
  • 这是有道理的。我非常着迷于将资产物理“放置”到某个位置,因此我将这种想法带到了数据库中。谢谢。

标签: mysql database database-design relational-database


【解决方案1】:

你应该有一个location_type 表。

location_type_id    location_type
      1             Rack
      2             Desk
      3             Storage

如果您以后想添加另一个location_type,例如ex: 'truck',这也有好处,您不必修改数据库,只需添加一个新的type

而不是RackDeskStorage 单个表location 的多个表

location_id      location_type_id  name
    1                  1           'Im a Rack'
    2                  1           'Im another Rack'
    3                  2           'Im just a desk'

最后是你的Assets

barcode          location_id
 xxxxxx              1            -- is in first rack
 yyyyyy              2            -- is in the second rack

【讨论】:

  • 我喜欢这个。我的表格比我展示的要复杂一些,但我会看看如何将这些想法付诸实践。谢谢。
猜你喜欢
  • 1970-01-01
  • 2018-08-27
  • 2011-09-30
  • 2011-11-15
  • 2010-09-22
  • 2013-09-25
相关资源
最近更新 更多