仓库表
仓库表
仓库关联商品表
CREATE TABLE `t_warehouse`(
`id` INT UNSIGNED PRIMARY KEY AUTO_INCREMENT COMMENT '主键',
`city_id` INT UNSIGNED NOT NULL COMMENT '城市ID', # 给城市定义索引
`address` VARCHAR(200) NOT NULL COMMENT '仓库地址',
`tel` VARCHAR(16) NOT NULL COMMENT '仓库电话',
INDEX idx_city_id(`city_id`)
) COMMENT = '仓库表';
仓库关联库存
CREATE TABLE `t_warehouse_sku`(
`sku_id` INT UNSIGNED NOT NULL COMMENT '商品ID',
`warehouse_id` INT UNSIGNED NOT NULL COMMENT '仓库ID',
`number` INT UNSIGNED NOT NULL COMMENT '库存数量',
`unit` VARCHAR(10) NOT NULL COMMENT '单位',
PRIMARY KEY(`warehouse_id`, `sku_id`) # 复合ID
) COMMENT = '仓库商品关联表';
门店表
CREATE TABLE `t_shop`
(
`id` INT UNSIGNED PRIMARY KEY AUTO_INCREMENT COMMENT '主键',
`city_id` INT UNSIGNED NOT NULL COMMENT '城市ID',
`address` VARCHAR(200) NOT NULL COMMENT '地址',
`tel` VARCHAR(16) NOT NULL COMMENT '电话',
INDEX idx_city_id (`city_id`) # 复合主键
) COMMENT = '门店表';
门店关联库存
# 门店商品库存
CREATE TABLE `t_shop_sku`
(
`shop_id` INT UNSIGNED COMMENT '门店ID',
`sku_id` INT UNSIGNED COMMENT '商品ID',
`number` INT UNSIGNED NOT NULL COMMENT '库存数量',
`unit` VARCHAR(10) NOT NULL COMMENT '库存单位',
PRIMARY KEY (`shop_id`, `sku_id`) # 复合主键
) COMMENT = '门店商品库存表';
门店与仓库的关系
零售店与仓库的对应关系
- 一个零售店的商品可以来源于多个仓库
- 一个仓库供应多个门店
门店与仓库关系&门店与商品的关系
- 一种商品可以在多个零售店销售
- 零售店的库存 & 仓库的库存