其他分享
首页 > 其他分享> > 外键变种

外键变种

作者:互联网

一对一

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视频整理 

标签:变种,int,primary,外键,char,key,null,id
来源: https://www.cnblogs.com/sparkss/p/11346755.html