一对一的外键关联实质就是特殊的多对一的外键关联
创建一张人员表
create table tb_person
(
person_id int auto_incremnet,
person_name varchar(50),
primary key (pid)
);
在创建一张身份证的表:
create table tb_card
(
card_id int auto_incremnet,
card_number char(18) not null,
police_station not null,
expir date not null,
person_id int not null,
primary key (card_id)
);
先添加外键约束
alter table tb_card add constraint fk_card_person_id foreign key (person_id) references tb_person (person_id);
再添加唯一性约束
alter table tb_card add constraint uni_card_id unique (person_id);
现在这两张表就拥有一对一的外键关联