智能点餐mysql框架图_SpringBoot微信点餐系统--P3数据库设计

08ba961da018ab4b4a90afa6343f7059.png

数据库字符编码设置为utf8mb4,为什么用utf8mb4呢?

1、为什么会有UTF8MB4?

可以简单的理解 utf8mb4 是目前最大的一个字符编码,支持任意文字.

低版本的MySQL支持的utf8编码,最大字符长度为 3 字节,如果遇到 4 字节的字符就会出现错误了。3个字节的 UTF-8 最大能编码的Unicode字符是 0xFFFF,也就是Unicode中的基本多文平面(BMP)。也就是说,任何不在基本多文平面的Unicode字符,都无法使用MySQL原有的 utf8 字符集存储。这些不在BMP中的字符包括哪些呢?最常见的就是Emoji 表情(Emoji 是一种特殊的 Unicode 编码,常见于 ios 和 android 手机上),和一些不常用的汉字,以及任何新增的 Unicode 字符等等。

理论上将,UTF-8 格式使用一至六个字节,最大能编码 31 位字符。最新的 UTF-8 规范只使用一到四个字节,最大能编码21位,正好能够表示所有的 17个 Unicode 平面。而utf8 则是 Mysql 早期版本中支持的一种字符集,只支持最长三个字节的 UTF-8字符,也就是 Unicode 中的基本多文本平面。这可能是因为在MySQL发布初期,基本多文种平面之外的字符确实很少用到。而在MySQL5.5.3版本后,要在 Mysql 中保存 4 字节长度的 UTF-8 字符,就可以使用 utf8mb4 字符集了。例如可以用utf8mb4字符编码直接存储emoj表情,而不是存表情的替换字符。

为了获取更好的兼容性,应该总是使用 utf8mb4 而非 utf8,事实上,最新版的phpmyadmin默认字符集就是utf8mb4。诚然,对于 CHAR 类型数据,使用utf8mb4 存储会多消耗一些空间。

那么utf8mb4比utf8多了什么的呢?多了emoji编码支持.如果实际用途上来看,可以给要用到emoji的库或者说表,设置utf8mb4.

建议普通表使用utf8 如果这个表需要支持emoji就使用utf8mb4

2、新建mysql库或者表的时候还有一个排序规则

utf8_unicode_ci比较准确,utf8_general_ci速度比较快。通常情况下utf8_unicode_ci的准确性就够我们用的了,在我看过很多程序源码后,发现它们大多数也用的是utf8_general_ci,所以新建数据 库时一般选用utf8_general_ci就可以了,如果是utf8mb4那么对应的就是 utf8mb4_general_ci utf8mb4_unicode_ci

原文链接

1、商品表

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

如果订单量太大,product_id不适合自增,无法存储

涉及到财务计算的一般用decimal(8,2)

2、类目表

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

3、订单表

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

4、订单详情表

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值