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

总结

相关推荐
Zoey的笔记本18 分钟前
2026告别僵化工作流:支持自定义字段的看板工具选型与部署指南
大数据·前端·数据库
静听山水18 分钟前
docker安装starrocks
数据库
学编程的小程1 小时前
从“兼容”到“超越”:金仓KESBSON引擎如何借多模融合改写文档数据库规则
数据库
千层冷面1 小时前
数据库分库分表
java·数据库·mysql·oracle
DBA小马哥1 小时前
金仓数据库引领国产化替代新范式:构建高效、安全的文档型数据库迁移解决方案
数据库·安全·mongodb·dba·迁移学习
企业对冲系统官2 小时前
基差风险管理系统日志分析功能的架构与实现
大数据·网络·数据库·算法·github·动态规划
冉冰学姐2 小时前
SSM学毕电设信息采集系统74v6w(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面
数据库·学生管理·ssm 框架应用·学毕电设·信息采集系统
茁壮成长的露露2 小时前
MongoDB备份恢复工具mongodump、mongorestore
数据库·mongodb
香气袭人知骤暖2 小时前
SQL慢查询常见优化步骤
android·数据库·sql
Star Learning Python2 小时前
MySQL日期时间的处理函数
数据库·sql