咸鱼翻身计划——仿天猫的springboot(后台管理第一天)

174 阅读1分钟

先分析,每个表之间的关系 image.png 分析完后,先建数据库,接着建表,建表的顺序很重要,需要将被外键(如果公共关键字在一个关系中是主关键字,那么这个公共关键字被称为另一个关系的外键。)指向的表先建,然后是其他的表。

顺序是:用户表》分类表》属性表》产品表》属性值表》产品图片表》评价表》订单表》订单项表表

CREATE DATABASE tianmao_springboot DEFAULT CHARACTER SET utf8;
use tianmao_springboot;
CREATE TABLE user (
        id int(11) not null atuo_indcremnt,
        name varchar(255) not null,
        password varchar(255) no null,
        salt varchar(255) default null,
        primary key(id)
}endgine=innobo default charset=utf8;

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;

fk_property_category FOREIGN KEY (cid) REFERENCES category (id) 是将两个表链接起来,链接的外键字段是id

ENGINE=InnoDB使用baiinnodb引擎

DEFAULT CHARSET=utf8 数据库默du认编码为utf-8

其他数据库代码与上面类似,请自行敲阅