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 '套餐菜品关系表';

总结

相关推荐
2401_8676239811 分钟前
SQL如何提取分组中的第一条记录_使用ROW_NUMBER定位数据
jvm·数据库·python
lifewange16 分钟前
Hive 数据库 增删改 完整操作指南
数据库·hive·hadoop
Mike117.20 分钟前
GBase 8c 写入高峰抖一下,我通常会先看检查点和 WAL
数据库
C137的本贾尼29 分钟前
子查询与合并查询:SQL 的高级过滤技巧
数据库·sql
jingyu飞鸟1 小时前
linux系统二进制安装MySQL 8.4、8.0版本数据库,配置crontab和xtrabackup数据库热备份脚本
linux·数据库·mysql
小江的记录本1 小时前
【MySQL】《MySQL日志面试背诵版+思维导图》(核心考点 + MySQL 8.0最新优化)
java·数据库·后端·python·sql·mysql·面试
BD_Marathon1 小时前
SQL学习指南——创建和填充数据库
数据库·sql
TDengine (老段)1 小时前
TDengine RPC 通信层深度解析 — 协议格式、连接管理与重试机制
大数据·数据库·rpc·架构·时序数据库·tdengine·涛思数据
KaMeidebaby1 小时前
卡梅德生物技术快报|噬菌体筛选全流程技术方案:弧菌抑菌菌株筛选、特性鉴定与效果测试
前端·数据库·其他·百度·新浪微博
蜀道山老天师1 小时前
从零搭建 Prometheus 监控 MySQL:含二进制安装、授权、exporter 配置全流程
运维·数据库·mysql·adb·云原生·prometheus