天猫整站Springboot 从零开始搭建(四(1))

2.2.2 用户表

mysql> create table user(
    -> id int(11) not null auto_increment,
    -> name varchar(255) default null,
    -> password varchar(255) default null,
    -> salt varchar(255) default null,
    -> primary key (id)
    -> )engine=InnoDB default charset=utf8;

2.2.3 分类表

mysql> create table category(
    -> id int(11) not null auto_increment,
    -> name varchar(255) default null,
    -> primary key (id)
    -> )engine=InnoDB default charset=utf8;

2.2.4 属性表

从这个表开始, 就有外键约束了。
本表的外键cid,指向分类表的id字段

mysql> create table property(
    -> id int(11) not null auto_increment,
    -> cid int(11) default null,
    -> name varchar(255) default null,
    -> primary key (id),
    -> constraint fk_property_category foreign key (cid) references category (id)
    -> ) engine=InnoDB default charset=utf8;

2.2.5 产品表

产品表字段稍多,讲解一下
name: 产品名称
subTitle: 小标题
originalPrice: 原始价格
promotePrice: 优惠价格
stock: 库存
createDate: 创建日期

本表的外键cid,指向分类表的id字段

CREATE TABLE product (
  id int(11) NOT NULL AUTO_INCREMENT,
  name varchar(255) DEFAULT NULL,
  subTitle varchar(255) DEFAULT NULL,
  originalPrice float DEFAULT NULL,
  promotePrice float DEFAULT NULL,
  stock int(11) DEFAULT NULL,
  cid int(11) DEFAULT NULL,
  createDate datetime DEFAULT NULL,
  PRIMARY KEY (id),
  CONSTRAINT fk_product_category FOREIGN KEY (cid) REFERENCES category (id)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

 

2.2.6 属性值表

在产品页的商品详情标签下,显示本产品的所有属性值

本表有两个外键
外键ptid,指向属性表的id字段
外键pid,指向产品表的id字段

mysql> create table propertyvalue(
    -> id int(11) not null auto_increment,
    -> pid int(11) default null,
    -> ptid int(11) default null,
    -> value varchar(255) default null,
    -> primary key(id),
    -> constraint fk_propertyvalue_property foreign key (ptid) references property(id),
    -> constraint fk_propertyvalue_product foreign key (pid) references product(id)
    -> )engine=InnoDB default charset=utf8;

2.2.7 产品图片表

在产品页显示5个单个图片

type表示类型,产品图片分单个图片和详情图片两种
本表的外键pid,指向产品表的id字段

CREATE TABLE productimage (
  id int(11) NOT NULL AUTO_INCREMENT,
  pid int(11) DEFAULT NULL,
  type varchar(255) DEFAULT NULL,
  PRIMARY KEY (id),
  CONSTRAINT fk_productimage_product FOREIGN KEY (pid) REFERENCES product (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

2.2.8 评价表

外键pid,指向产品表的id字段
外键uid,指向用户表的id字段

CREATE TABLE review (
  id int(11) NOT NULL AUTO_INCREMENT,
  content varchar(4000) DEFAULT NULL,
  uid int(11) DEFAULT NULL,
  pid int(11) DEFAULT NULL,
  createDate datetime DEFAULT NULL,
  PRIMARY KEY (id),
  CONSTRAINT fk_review_product FOREIGN KEY (pid) REFERENCES product (id),
    CONSTRAINT fk_review_user FOREIGN KEY (uid) REFERENCES user (id)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

2.2.9 订单表

订单表的字段也比较多,讲解一下:
orderCode: 订单号
address:收货地址
post: 邮编
receiver: 收货人信息
mobile: 手机号码
userMessage: 用户备注信息
createDate: 订单创建日期
payDate: 支付日期
deliveryDate: 发货日期
confirmDate:确认收货日期
status: 订单状态
外键uid,指向用户表id字段

CREATE TABLE order_ (
  id int(11) NOT NULL AUTO_INCREMENT,
  orderCode varchar(255) DEFAULT NULL,
  address varchar(255) DEFAULT NULL,
  post varchar(255) DEFAULT NULL,
  receiver varchar(255) DEFAULT NULL,
  mobile varchar(255) DEFAULT NULL,
  userMessage varchar(255) DEFAULT NULL,
  createDate datetime DEFAULT NULL,
  payDate datetime DEFAULT NULL,
  deliveryDate datetime DEFAULT NULL,
  confirmDate datetime DEFAULT NULL,
  uid int(11) DEFAULT NULL,
  status varchar(255) DEFAULT NULL,
  PRIMARY KEY (id),
  CONSTRAINT fk_order_user FOREIGN KEY (uid) REFERENCES user (id)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

2.2.10 订单项表

这个表是外键最多的一个表
外键pid,指向产品表id字段
外键oid,指向订单表id字段
外键uid,指向用户表id字段
number字段表示购买数量

CREATE TABLE orderitem (
  id int(11) NOT NULL AUTO_INCREMENT,
  pid int(11) DEFAULT NULL,
  oid int(11) DEFAULT NULL,
  uid int(11) DEFAULT NULL,
  number int(11) DEFAULT NULL,
  PRIMARY KEY (id),
  CONSTRAINT fk_orderitem_user FOREIGN KEY (uid) REFERENCES user (id),
  CONSTRAINT fk_orderitem_product FOREIGN KEY (pid) REFERENCES product (id),
  CONSTRAINT fk_orderitem_order FOREIGN KEY (oid) REFERENCES order_ (id)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Baymax_wyl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值