MySQL-21.多表设计-案例-关系分析-表结构

一.参考页面原型及需求,设计合理的表结构

二.创建category表

sql 复制代码
create table catagory
(
    id          int unsigned auto_increment comment '主键ID'
        primary key,
    name        varchar(20)      not null comment '分类名称',
    type        tinyint unsigned not null comment '类型:1.菜品分类,2.tao''cuo',
    sort        tinyint unsigned not null comment '排序字段',
    status      tinyint unsigned not null comment '状态字段:0.停用。1.启用',
    create_time datetime         not null comment '创建时间',
    update_time datetime         not null comment '更新时间',
    constraint catagory_pk2
        unique (name)
)
    comment '分类表';

三.创建dish表

sql 复制代码
create table dish
(
    id          int unsigned auto_increment
        primary key,
    name        varchar(20)                  not null comment '菜品名称',
    category_id int unsigned                 not null,
    price       decimal(8, 2)                not null,
    image       varchar(300)                 not null comment '图片url',
    description varchar(200)                 null comment '描述信息',
    stutus      tinyint unsigned default '0' not null comment '状态.0:停售,1:起售',
    create_time datetime                     not null comment '创建时间',
    update_time datetime                     not null comment '修改时间',
    constraint dish_pk2
        unique (name)
)
    comment '菜品表';

三.套餐表-setmeal

sql 复制代码
create table setmeal
(
    id          int unsigned auto_increment comment '主键ID'
        primary key,
    name        varchar(20)                  not null comment '套餐名称',
    category_id int unsigned                 not null comment '套餐分类ID',
    price       decimal(8, 2)                not null comment '价格',
    image       varchar(300)                 not null comment '图片url',
    description varchar(200)                 null comment '描述信息',
    status      tinyint unsigned default '0' not null comment '状态,0:停售,1:起售',
    create_time datetime                     not null comment '创建时间',
    update_time datetime                     not null comment '修改时间',
    constraint setmeal_pk2
        unique (name)
)
    comment '套餐表';

四.套餐菜品关系表 setmeal_dish

sql 复制代码
create table setmeal_dish
(
    id         int unsigned auto_increment comment '主键id',
    setmeal_id int unsigned     not null comment '套餐id',
    dish_id    int unsigned     not null comment '菜品ID',
    copies     tinyint unsigned not null comment '菜品的份数',
    constraint setmeal_dish_pk
        primary key (id)
)
    comment '套餐菜品关系表';

总结

相关推荐
gQ85v10Db2 分钟前
Redis分布式锁进阶第十六篇:番外高阶避坑篇 + 隐性埋点锁故障深挖 + 疑难杂症终极兜底方案
数据库·redis·分布式
S1998_1997111609•X9 分钟前
论恶意注入污染蜜罐进程函数值取仺⺋以集团犯罪获取数据爬虫的轮系依据
网络·数据库·爬虫·网络协议·百度
许彰午12 分钟前
# 从OOM到根治的完整过程——导出大数据的应急、根因分析与游标方案
java·大数据·数据库·系统架构
eLIN TECE25 分钟前
nacos2.3.0 接入pgsql或其他数据库
数据库
曾几何时`44 分钟前
MySQL(七)索引
数据库·mysql
KmSH8umpK1 小时前
Redis分布式锁从原生手写到Redisson高阶落地,附线上死锁复盘优化方案进阶第九篇
数据库·redis·分布式
悠悠121381 小时前
一条 SQL 从敲下回车,到在 MySQL 里“跑完一生”,中间到底经历了啥?
数据库·sql·mysql
秋91 小时前
MySQL 9.7.0 使用详解:新特性、实战与避坑指南
android·数据库·mysql
S1998_1997111609•X1 小时前
恶意注入污染蜜罐HDMI进程函数值进行封禁垃圾蠕虫仓蟲的轮系依据行为戆直㞢仓shell token
数据库·爬虫·网络协议·百度·开闭原则
Yupureki2 小时前
《Redis数据库》1.初识Redis
数据库·redis·缓存