create table tb_order( id int PRIMARY key auto_increment, payment double(10,2), payment_type tinyint, status Tinyint ); create table tb_goods( id int PRIMARY key auto_increment, title varchar(100), price double(10,2) ); create table tb_order_goods( id int PRIMARY key auto_increment, order_id int, goods_id int, count int );
alter table tb_order_goods add CONSTRAINT fk_order_goods_1 FOREIGN key (order_id) REFERENCES tb_order(id); alter table tb_order_goods add CONSTRAINT fk_order_goods_2 FOREIGN key (goods_id) REFERENCES tb_goods(id);
1. create table tb_user( id int PRIMARY key auto_increment, photo MEDIUMBLOB, nickname varchar(20), age int, gender varchar(1), desc_id int );
2. create table tb_user_desc( id int PRIMARY key auto_increment, city varchar(10), edu varchar(20), income double(15,2), status tinyint );
3. alter table tb_user add CONSTRAINT fk_tb_user_tb_user_desc FOREIGN key(desc_id) REFERENCES tb_user_desc(id);
4. alter table tb_user MODIFY desc_id int unique;