When you need to create two tables with a one to one relationship, such as creating and wife hansband table, the two tables inside a records should
One to one relationship. Therefore, in order to ensure that such a one to one relationship we still need to use a foreign key constraint, the wife of the primary key table inside to outside
Key, object reference table inside for hasband primary key.
At this time, the wife inside the table primary key column, wherein the primary key must be met, unique, non-null, references. This ensures that each record in the table are
Only, thus ensuring each record two tables which are one to one.
SQL statement is as follows:
hasband table:
create table hansband(
hid int primary key auto_increment,
hname varchar (50)
);
wife table:
create table wife(
wid int primary key auto_increment,
wname varchar(50),
constraint fk_wife_hasband foreign key(wid) references hasband(hid)
);