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

总结

相关推荐
ZWZhangYu4 小时前
LangChain 构建向量数据库和检索器
数据库·langchain·easyui
feifeigo1235 小时前
升级到MySQL 8.4,MySQL启动报错:io_setup() failed with EAGAIN
数据库·mysql·adb
火龙谷7 小时前
【nosql】有哪些非关系型数据库?
数据库·nosql
焱焱枫7 小时前
Oracle获取执行计划之10046 技术详解
数据库·oracle
qq_392397129 小时前
Redis常用操作
数据库·redis·wpf
A__tao10 小时前
一键将 SQL 转为 Java 实体类,全面支持 MySQL / PostgreSQL / Oracle!
java·sql·mysql
一只fish11 小时前
MySQL 8.0 OCP 1Z0-908 题目解析(17)
数据库·mysql
花好月圆春祺夏安11 小时前
基于odoo17的设计模式详解---装饰模式
数据库·python·设计模式
A__tao11 小时前
SQL 转 Java 实体类工具
java·数据库·sql
m0_6530313611 小时前
腾讯云认证考试报名 - TDSQL数据库交付运维专家(TCCE PostgreSQL版)
运维·数据库·腾讯云