一对一

create table userinfo1(
id int auto_increment primary key,
name char(10),
gender char(10),
email varchar(64))engine=innodb default charset=utf8;

create table admin(
id int auto_increment primary key,
user_id int not null,unique uq_ul (user_id),constraint fk_admin_u1 foreign key (user_id) references userinfo1(id),
password varchar(64) not null)engine=innodb default charset=utf8;

 

多对多

 

 

create table userinfo2(
id int auto_increment primary key,
name char(10) not null,
gender char(10) not null,
email varchar(10))engine=innodb default charset=utf8;

create table host(
id int auto_increment primary key,
hostname char(64))engine=innodb default charset=utf8;

create table user2host(
id int auto_increment primary key,
userid int not null,
hostid int not null,
unique uq_user_host (userid,hostid),
constraint fk_u2h_user foreign key (userid) references userinfo2(id),
constraint fk_u2h_host foreign key (hostid) references host(id)
)engine=innodb default charset=utf8;

 

* 参考oldboy视频整理 

posted on 2019-08-13 16:59  Mr_星火  阅读(151)  评论(0编辑  收藏  举报