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

总结

相关推荐
web1309332039833 分钟前
Mysql的安装配置教程(非常详细)从零基础入门到精通,看完这一篇就够了
数据库·mysql
三天不学习34 分钟前
浅析AI大模型为何需要向量数据库?【入门基础】
数据库·人工智能·欧氏距离·向量数据库·余弦相似度
MonkeyKing_sunyuhua36 分钟前
将数据库结构化数据整合到RAG问答中的方式
数据库
喝醉酒的小白37 分钟前
MySQL内存使用率高问题排查与解决方案:
数据库
鹅鹅鹅呢38 分钟前
mysql 登录报错:ERROR 1045(28000):Access denied for user ‘root‘@‘localhost‘ (using password Yes)
android·数据库·mysql
摘星编程39 分钟前
Redis+Caffeine构建高性能二级缓存
数据库·redis·缓存
在人间负债^41 分钟前
假装自己是个小白 ---- 重新认识MySQL
android·数据库·mysql
檀越剑指大厂42 分钟前
【PostgreSQL系列】PostgreSQL性能优化
数据库·postgresql·性能优化
Leo.yuan1 小时前
3D 数据可视化系统是什么?具体应用在哪方面?
大数据·数据库·3d·信息可视化·数据分析
元亓亓亓1 小时前
MySQL--day1--数据库概述
数据库·mysql