网上外卖及订餐系统的数据库设计

背景:互联网越来越发达,宅男越来越宅,网上订餐送叫外卖的越来越多.

注:本文仅做后台数据库设计,不做系统功能设计.


一、数据库需求分析

1、用户分为游客、注册用户和管理员用户,只有登录用户才能进行网上订餐,游客仅能浏览餐厅及菜肴信息,只有管理员身份才能进行后台管理

2、一个餐厅设计一张菜单;一张订单对应一个送餐员,可以包含多个菜肴;一个客服管理员可以管理多张订单

3、每个菜肴从属于一个菜系,一个菜单,一个餐厅

4、一个用户可以选择多个菜肴,产生多个订单

5、一张菜单每次对应一个优惠活动


二、数据表属性

地区:城市编码、城市名、区县编码、区县名、乡镇编码、乡镇名、街道编码、街道名

用户:用户标识、用户名、联系电话、性别、年龄、身份证、地址、登陆账号、登录密码、QQ、用户状态、注册时间、销户时间

订单:订单编号、订单状态、下单时间、退单时间、预计送达时间、送餐地址

菜单:菜肴编号、菜肴名称、菜肴原价、菜肴介绍、菜系分类、菜肴图片

优惠活动:优惠活动编号、优惠活动名称、优惠活动描述、开始时间、结束时间、活动状态、优惠类型、优惠折扣、优惠后价格

餐厅:餐厅编号、餐厅名称、订餐电话、送餐范围、送餐收费标准、餐厅地址、餐厅负责人、支持的支付方式、餐厅描述

送餐员:送餐员编号、送餐员姓名、联系电话、入职时间、离职时间、在职状态、工资、家庭住址

管理员:管理员编号、管理员名称、联系电话、管理员账号、管理员密码、管理权限


三、实体间联系

地区--用户

用户--订单

订单--菜单

订单--送餐员

菜单--优惠活动

菜单--餐厅

餐厅--送餐员

餐厅--管理员


四、概念数据模型设计(Conceptual Data Model)

173253_lers_144859.jpg


五、逻辑数据模型设计(Logical Data Model)

173253_EZgT_144859.jpg


六、物理数据模型设计(Physical Data Model)

173254_AN2E_144859.jpg


六、创建表SQL(数据库环境:PostgreSQL)

/*==============================================================*/
/* Table: deliver                                               */
/*==============================================================*/
create table deliver (
   deliver_id           NUMERIC(8)           not null,
   restaurant_id        NUMERIC(8)           null,
   deliver_name         VARCHAR(32)          null,
   deliver_tel          VARCHAR(16)          null,
   employ_date          DATE                 null,
   fire_date            DATE                 null,
   deliver_status       VARCHAR(8)           null,
   salary               NUMERIC(8,2)         null,
   home_addr            VARCHAR(256)         null,
   constraint PK_DELIVER primary key (deliver_id)
);

comment on table deliver is
'送餐员信息表';

/*==============================================================*/
/* Index: deliver_PK                                            */
/*==============================================================*/
create unique index deliver_PK on deliver (
deliver_id
);

/*==============================================================*/
/* Index: "餐厅-送餐员_FK"                                           */
/*==============================================================*/
create  index "餐厅-送餐员_FK" on deliver (
restaurant_id
);

/*==============================================================*/
/* Table: discount                                              */
/*==============================================================*/
create table discount (
   discount_id          NUMERIC(8)           not null,
   discount_name        VARCHAR(32)          null,
   discount_desc        VARCHAR(256)         null,
   start_time           DATE                 null,
   end_time             DATE                 null,
   discount_status      VARCHAR(8)           null,
   discount_type        VARCHAR(32)          null,
   discount_percent     NUMERIC(4)           null,
   discount_price       NUMERIC(8,2)         null,
   constraint PK_DISCOUNT primary key (discount_id)
);

comment on table discount is
'优惠信息表';

/*==============================================================*/
/* Index: discount_PK                                           */
/*==============================================================*/
create unique index discount_PK on discount (
discount_id
);

/*==============================================================*/
/* Table: manager                                               */
/*==============================================================*/
create table manager (
   mgr_id               NUMERIC(8)           not null,
   restaurant_id        NUMERIC(8)           null,
   mgr_name             VARCHAR(16)          null,
   mgr_tel              VARCHAR(16)          null,
   mgr_loginname        VARCHAR(32)          null,
   mgr_password         VARCHAR(32)          null,
   privilege            VARCHAR(8)           null,
   constraint PK_MANAGER primary key (mgr_id)
);

comment on table manager is
'管理员信息表';

/*==============================================================*/
/* Index: manager_PK                                            */
/*==============================================================*/
create unique index manager_PK on manager (
mgr_id
);

/*==============================================================*/
/* Index: "餐厅-管理员_FK"                                           */
/*==============================================================*/
create  index "餐厅-管理员_FK" on manager (
restaurant_id
);

/*==============================================================*/
/* Table: medu                                                  */
/*==============================================================*/
create table medu (
   dish_id              NUMERIC(8)           not null,
   restaurant_id        NUMERIC(8)           null,
   discount_id          NUMERIC(8)           null,
   dish_name            VARCHAR(16)          null,
   original_price       NUMERIC(8,2)         null,
   dish_desc            VARCHAR(256)         null,
   dish_class           VARCHAR(16)          null,
   dish_picture         CHAR(16)             null,
   constraint PK_MEDU primary key (dish_id)
);

comment on table medu is
'菜单信息表';

/*==============================================================*/
/* Index: medu_PK                                               */
/*==============================================================*/
create unique index medu_PK on medu (
dish_id
);

/*==============================================================*/
/* Index: 设计_FK                                                 */
/*==============================================================*/
create  index 设计_FK on medu (
restaurant_id
);

/*==============================================================*/
/* Index: "优惠活动-菜单_FK"                                          */
/*==============================================================*/
create  index "优惠活动-菜单_FK" on medu (
discount_id
);

/*==============================================================*/
/* Table: "order"                                               */
/*==============================================================*/
create table "order" (
   order_id             NUMERIC(32)          not null,
   dish_id              NUMERIC(8)           null,
   deliver_id           NUMERIC(8)           null,
   user_id              NUMERIC(16)          null,
   order_status         VARCHAR(8)           null,
   create_date          DATE                 null,
   end_date             DATE                 null,
   expect_date          DATE                 null,
   send_addr            VARCHAR(256)         null,
   constraint PK_ORDER primary key (order_id)
);

comment on table "order" is
'订单信息表';

/*==============================================================*/
/* Index: order_PK                                              */
/*==============================================================*/
create unique index order_PK on "order" (
order_id
);

/*==============================================================*/
/* Index: "用户-订单_FK"                                            */
/*==============================================================*/
create  index "用户-订单_FK" on "order" (
user_id
);

/*==============================================================*/
/* Index: "订单-菜单_FK"                                            */
/*==============================================================*/
create  index "订单-菜单_FK" on "order" (
dish_id
);

/*==============================================================*/
/* Index: "订单-送餐员_FK"                                           */
/*==============================================================*/
create  index "订单-送餐员_FK" on "order" (
deliver_id
);

/*==============================================================*/
/* Table: region                                                */
/*==============================================================*/
create table region (
   city_id              NUMERIC(8)           null,
   city_name            VARCHAR(32)          null,
   area_id              NUMERIC(8)           not null,
   area_name            VARCHAR(32)          null,
   town_id              NUMERIC(8)           null,
   town_name            VARCHAR(32)          null,
   street_id            NUMERIC(16)          null,
   street_name          VARCHAR(256)         null,
   constraint PK_REGION primary key (area_id)
);

comment on table region is
'地区信息表';

/*==============================================================*/
/* Index: region_PK                                             */
/*==============================================================*/
create unique index region_PK on region (
area_id
);

/*==============================================================*/
/* Table: restaurant                                            */
/*==============================================================*/
create table restaurant (
   restaurant_id        NUMERIC(8)           not null,
   dish_id              NUMERIC(8)           null,
   restaurant_name      VARCHAR(32)          null,
   contect_tel          VARCHAR(16)          null,
   range                VARCHAR(256)         null,
   fee_standard         VARCHAR(32)          null,
   restaurant_addr      VARCHAR(256)         null,
   owner_name           VARCHAR(16)          null,
   support_paytype      VARCHAR(32)          null,
   restaurant_desc      VARCHAR(256)         null,
   constraint PK_RESTAURANT primary key (restaurant_id)
);

comment on table restaurant is
'餐厅信息表';

/*==============================================================*/
/* Index: restaurant_PK                                         */
/*==============================================================*/
create unique index restaurant_PK on restaurant (
restaurant_id
);

/*==============================================================*/
/* Index: 属于_FK                                                 */
/*==============================================================*/
create  index 属于_FK on restaurant (
dish_id
);

/*==============================================================*/
/* Table: selection                                             */
/*==============================================================*/
create table selection (
   user_id              NUMERIC(16)          not null,
   dish_id              NUMERIC(8)           not null,
   cnt_dish             NUMERIC(4)           null,
   pay_type             VARCHAR(16)          null,
   remark               VARCHAR(256)         null,
   constraint PK_SELECTION primary key (user_id, dish_id)
);

comment on table selection is
'选菜';

/*==============================================================*/
/* Index: selection_PK                                          */
/*==============================================================*/
create unique index selection_PK on selection (
user_id,
dish_id
);

/*==============================================================*/
/* Index: selection_FK                                          */
/*==============================================================*/
create  index selection_FK on selection (
user_id
);

/*==============================================================*/
/* Index: selection2_FK                                         */
/*==============================================================*/
create  index selection2_FK on selection (
dish_id
);

/*==============================================================*/
/* Table: "user"                                                */
/*==============================================================*/
create table "user" (
   user_id              NUMERIC(16)          not null,
   area_id              NUMERIC(8)           null,
   user_name            VARCHAR(32)          null,
   msisdn               NUMERIC(16)          null,
   gender               VARCHAR(4)           null,
   age                  VARCHAR(4)           null,
   ic_no                VARCHAR(32)          null,
   address              VARCHAR(256)         null,
   login_name           VARCHAR(32)          null,
   password             VARCHAR(32)          null,
   qq                   VARCHAR(16)          null,
   user_status          NUMERIC(4)           null,
   reg_date             DATE                 null,
   terminate_date       DATE                 null,
   constraint PK_USER primary key (user_id)
);

comment on table "user" is
'用户信息表';

/*==============================================================*/
/* Index: user_PK                                               */
/*==============================================================*/
create unique index user_PK on "user" (
user_id
);

/*==============================================================*/
/* Index: "地区-用户_FK"                                            */
/*==============================================================*/
create  index "地区-用户_FK" on "user" (
area_id
);

alter table deliver
   add constraint "FK_DELIVER_餐厅-送餐员_RESTAURA" foreign key (restaurant_id)
      references restaurant (restaurant_id)
      on delete restrict on update restrict;

alter table manager
   add constraint "FK_MANAGER_餐厅-管理员_RESTAURA" foreign key (restaurant_id)
      references restaurant (restaurant_id)
      on delete restrict on update restrict;

alter table medu
   add constraint "FK_MEDU_优惠活动-菜单_DISCOUNT" foreign key (discount_id)
      references discount (discount_id)
      on delete restrict on update restrict;

alter table medu
   add constraint FK_MEDU_设计_RESTAURA foreign key (restaurant_id)
      references restaurant (restaurant_id)
      on delete restrict on update restrict;

alter table "order"
   add constraint "FK_ORDER_用户-订单_USER" foreign key (user_id)
      references "user" (user_id)
      on delete restrict on update restrict;

alter table "order"
   add constraint "FK_ORDER_订单-菜单_MEDU" foreign key (dish_id)
      references medu (dish_id)
      on delete restrict on update restrict;

alter table "order"
   add constraint "FK_ORDER_订单-送餐员_DELIVER" foreign key (deliver_id)
      references deliver (deliver_id)
      on delete restrict on update restrict;

alter table restaurant
   add constraint FK_RESTAURA_属于_MEDU foreign key (dish_id)
      references medu (dish_id)
      on delete restrict on update restrict;

alter table selection
   add constraint FK_SELECTIO_SELECTION_USER foreign key (user_id)
      references "user" (user_id)
      on delete restrict on update restrict;

alter table selection
   add constraint FK_SELECTIO_SELECTION_MEDU foreign key (dish_id)
      references medu (dish_id)
      on delete restrict on update restrict;

alter table "user"
   add constraint "FK_USER_地区-用户_REGION" foreign key (area_id)
      references region (area_id)
      on delete restrict on update restrict;


转载于:https://my.oschina.net/mysweet/blog/336303

  • 11
    点赞
  • 133
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值