微信点餐系统(一)建表的一些注意事项

 

商品表

SQL语句:

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 '商品表';

Tips:

1.创建时间 create_time 使用timestamp类型。设置默认值为当前时间:

default current_timestamp

2.更新时间 update_time 使用timestamp类型。设置默认值为当前时间,并让数据库自动设置更新时间为操作的当前时间:

default current_timestamp on update current_timestamp

只有Mysql5.7以上版本才支持default current_timestamp的写法

 

类目表

SQL语句:

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 '类目表';

Tips:

1.在商品中id过多一般不用int自增,但是在类目中,不会出现过多的id,可以使用int自增

2.在商品表中,会利用类目编号category_type到类目表中与表中相应字段对应查询数据,为提升性能可以给该字段加约束索引。

unique key `uqe_category_type` (`category_type`)

 

订单总表

SQL语句:

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 '订单主表';

Tips:

1、订单状态 order_status 状态值使用tinyint即可。
2、订单可能经常使用用户openid查询,所以给openid加索引。

key `idx_buyer_openid` (`buyer_openid`)

3.关于关键字tinyint的一些说明:

        tinyint可以存储1字节, 即unsigned 0~255(signed -127~127)。显示大小不受此限制 (所有整数类型相同),即使设为1,也可以存入和取出大于10的数。括号里的数字,即显示大小对整数来说主要有两个目的, 一是做为编码文档;将 tinyint (1) 放到表定义中会告诉人们只有数字 0 - 9 应该输入, 表没有被设计具有其他值。

        另一个目的是, 你可以与属性ZEROFILL联合使用。ZEROFILL将填充小于显示大小的数字,在他们面前补上零。例如 TINYINT (3) 与 ZEROFILL, 插入值4, 你会得到 004

 

订单详情表

SQL语句:

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 '订单详情表';

Tips:

1、查询订单详情会用到订单id,所以给订单id加索引

key `idx_order_id` (`order_id`)

建库:

新建数据库,编码选择utf8mb4 - utf8mb4_general_ci
该编码可以存储emoji表情。

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值