仓库的数据模型

时间:2012-01-15 11:29:26

标签: database database-design

我需要一个用于配置仓库的数据库。到目前为止,我有3张桌子:

  • 仓库(1)有很多车道(n)
  • 车道(1)有许多架子(n)
  • 架子(1)有许多架子

现在每个表都有明显的ID和描述/名称。

Shelves表包含一个stack_id(托盘),因此我可以跟踪哪些货架被取出以及哪些货架是免费的,哪个堆栈位于哪里。

我的一个问题是每条车道可能包含不同数量的货架。例如。车道A有10个机架,其中B车道有8个机架。所以只需设置一个简单的矩阵(车道*货架*货架不起作用)。

我需要能够计算。仓库占用,当然能够追踪特定堆栈的位置。

我的问题是:我真的需要为此使用3个单独的表吗?有没有更好的方法呢?

另一个问题是:如果选择的命名(车道,架子和货架)是正确的(我不是英语本地人)。

非常感谢提前!

1 个答案:

答案 0 :(得分:1)

如果车道可以有不同数量的机架,那么将这些信息存储在表格中是很有意义的。

-- Predicate: "Warehouse number <warehouse_num> is called <warehouse_name>."
create table warehouses (
  warehouse_num integer primary key,
  warehouse_name varchar(45) not null unique
);

-- Predicate: "Warehouse number <warehouse_num> contains lane <lane_num>."
-- This table allows different numbers of lanes per warehouse. If you change
-- the data type to, say, varchar(2) or varchar(3), you can accommodate 
-- different lane "names" in each warehouse. For example, one warehouse 
-- might name its lanes "Lane 1" and "Lane 2", while a different warehouse 
-- might use "Lane A" and "Lane B2".
create table lanes (
  warehouse_num integer not null references warehouses (warehouse_num),
  lane_num integer not null check (lane_num > 0),
  primary key (warehouse_num, lane_num)
);

-- Predicate: "Lane <lane_num> in warehouse <warehouse_num> contains rack 
-- <rack_num>."
-- Allows a different number of racks in each lane.
create table racks (
  warehouse_num integer not null,
  lane_num integer not null,
  rack_num integer not null check (rack_num > 0),
  primary key (warehouse_num, lane_num, rack_num),
  foreign key        (warehouse_num, lane_num) 
    references lanes (warehouse_num, lane_num)
);

-- Predicate: "Rack <rack_num> in lane <lane_num> in warehouse 
-- <warehouse_num> contains shelf <shelf_num>."  Allows a different
--  number of shelves in each rack.
create table shelves (
  warehouse_num integer not null,
  lane_num integer not null,
  rack_num integer not null,
  shelf_num integer not null check (shelf_num > 0),
  primary key (warehouse_num, lane_num, rack_num, shelf_num),
  foreign key        (warehouse_num, lane_num, rack_num) 
    references racks (warehouse_num, lane_num, rack_num)
);

-- "Contents" might be a better name than inventory.  You might also need 
-- a unique constraint on stack_id. 
-- Predicate: "Stack <stack_id> is stored in warehouse <warehouse_num> in lane 
-- <lane_num> in rack <rack_num> on shelf <shelf_num>."
create table inventory (
  warehouse_num integer not null,
  lane_num integer not null,
  rack_num integer not null,
  shelf_num integer not null,
  stack_id integer not null,
  primary key (warehouse_num, lane_num, rack_num, shelf_num, stack_id),
  foreign key (warehouse_num, lane_num, rack_num, shelf_num)
    references shelves (warehouse_num, lane_num, rack_num, shelf_num)
);

我假设车道,货架和货架都已编号。如果他们不是,请改用他们的名字。通过使用实际的通道名称,机架名称和货架名称而不是无意义的ID号,库存查询不需要连接来生成人类可读的结果。即使您的仓库是配送中心,它也会快速翻录。

表之间的外键约束为您提供了非常高的数据完整性,至少就识别货架,货架等而言。大多数只需要填充一次,并且仅在您重新配置仓库时才更新车道和货架。

术语:您的“车道”可能更常称为过道或行。我从来没有在英语中称为车道的仓库中看到过一排,但我明白你的意思。你建造这个的人会告诉你,如果你问他们。