-- 微信点餐数据库表设计
-- product_info商品表
-- product_category类目表
-- order_master订单主表
-- order_detail订单详情表
-- seller_info卖家信息表
-- 商品表 -- 主键:product_id -- 创建时间:默认当前时间default current_timestamp -- 修改时间:每次修改数据时,数据库自动修改为当前时间on update current_timestamp create table product_info ( product_id varchar(32) not null, product_name varchar(64) not null comment '商品名称', product_price decimal(8,2) not null comment '单价', product_stock int not null comment '库存', product_description varchar(64) comment '描述', product_icon varchar(512) comment '小图', category_type int not null comment '类目编号', create_time timestamp not null default current_timestamp comment '创建时间', update_time timestamp not null default current_timestamp on update current_timestamp comment '修改时间', primary key(product_id) )comment '商品表'; -- 类目表 -- 主键:category_id -- 约束索引:查询商品表product_info时,会通过类目编号category_type来查,因此类目编号是唯一的,不能出现两个相同的类目编号 create table product_category ( category_id int not null auto_increment, category_name varchar(64) not null comment '类目名字', category_type int not null comment '类目编号', create_time timestamp not null default current_timestamp comment '创建时间', update_time timestamp not null default current_timestamp on update current_timestamp comment '修改时间', primary key(category_id), unique key uqe_category_type (category_type) )comment '类目表'; -- 订单表 -- 主键:查询订单详情表order_detail时,会通过order_id来查订单表,所以要定义主键 -- 索引:查询卖家下了哪些订单seller_info时,要用buyer_openid来查 create table order_master ( order_id varchar(32) not null, buyer_name varchar(32) not null comment '买家名字', buyer_phone varchar(32) not null comment '买家电话', buyer_address varchar(128) not null comment '买家地址', buyer_openid varchar(64) not null comment '买家微信openid', order_amount decimal(8,2) not null comment '订单总金额', order_status tinyint(3) not null default '0' comment '订单状态,默认0新订单', pay_status tinyint(3) not null default '0' comment '支付状态,默认0未支付', create_time timestamp not null default current_timestamp comment '创建时间', update_time timestamp not null default current_timestamp on update current_timestamp comment '修改时间', primary key(order_id), key idx_buyer_openid(buyer_openid) )comment '订单表'; -- 订单详情表 -- 主键:查询订单详情表order_detail,需要通过detail_id来表 -- 索引:查询订单表时,会通过order_id来查 create table order_detail ( detail_id varchar(32) not null, order_id varchar(32) not null, product_id varchar(32) not null, product_name varchar(64) not null comment '商品名称', product_price decimal(8,2) not null comment '当前价格,单位分', product_quantity int not null comment '数量', product_icon varchar(512) comment '小图', create_time timestamp not null default current_timestamp comment '创建时间', update_time timestamp not null default current_timestamp on update current_timestamp comment '修改时间', primary key (detail_id), key idx_order_id (order_id) )comment '订单详情表'; -- 卖家(登录后台使用, 卖家登录之后可能直接采用微信扫码登录,不使用账号密码) create table seller_info ( id varchar(32) not null, username varchar(32) not null, password varchar(32) not null, openid varchar(64) not null comment '微信openid', create_time timestamp not null default current_timestamp comment '创建时间', update_time timestamp not null default current_timestamp on update current_timestamp comment '修改时间', primary key (id) ) comment '卖家信息表';