本例开始使用IDEA编写SQL代码,使用方法略
文章目录
多对多对应,需要建中间表使之对应
create database db_design;
show databases;
use db_design;
-- 多对多关系
drop table if exists orders_and_goods;
drop table if exists orders;
drop table if exists goods;
-- 订单表
create table orders
(
id int primary key auto_increment,
payment double(10, 2),
payment_way tinyint,
status tinyint
);
-- 商品表
create table goods
(
id int primary key auto_increment,
title varchar(100),
price double(10, 2)
);
-- 中间表
create table orders_and_goods
(
id int primary key auto_increment,
order_id int,
good_id int,
count int
);
show tables ;
alter table orders_and_goods