收银台项目(二):数据表的设计
一、用户表
--创建用户表 create table users ( user_id int primary key auto_increment, username varchar(50) not null unique, password char(60) not null )comment用户表,密码保存的是一个利用加密算法加密之后的字符串;
二、商品表
--创建商品表 create table products ( pro_id int primary key auto_increment, user_id int not null comment 记录该商品是由那个用户上架的, pro_name varchar(100) not null, introduce varchar (200) not null comment 商品介绍, stock int not null comment 显示单位, price int not null comment 价格,单位是分,100表示一块钱, discount int not null comment 折扣,取值范围(0,100] );
三、订单表
--创建订单表 create table orders ( order_id int primary key auto_increment, user_id int not null comment 记录是由哪一个用户结算, uuid char(32) not null unique comment 订单编号, create_time datetime not null comment 下单时间, finished_time datetime null default null comment 完成时间, payable int not null comment 应该支付的金额, actual int not null comment 实付金额, status int not null comment 进行中1|完成2 );
四、商品和订单的对应表
在订单浏览中,我们需要展示订单的信息以及购买的商品的信息,为了方式我们下架商品之后商品信息丢失,我们需要用一张商品信息和订单的对应表来存储信息
--订单和商品信息的关系表,防止商品下架之后商品信息消失 --所以利用一张表记录对应的信息 create table `order` ( id int primary key auto_increment, order_id int not null comment 属于哪个订单, pro_id int not null comment 哪个商品, pro_name varchar(100) not null, pro_introduce varchar(200) not null, pro_number int not null comment 本次订单购买这个商品的数量, pro_unit varchar(10) not null comment 单位, pro_price int not null comment 单价, pro_discount int not null comment 折扣 );