CREATE TABLE people (
id int not null auto_increment primary key,
name varchar(255) not null,
);
CREATE TABLE phone_numbers (
id int not null auto_increment primary key,
people_id int not null,
phone_number varchar(32) not null,
FOREIGN KEY fk_ppkey(people_id)
REFERENCES people(id)
ON UPDATE CASCADE
ON DELETE RESTRICT
);
1条答案
按热度按时间332nm8kg1#
它们被称为外键,你可以在网上找到很多教程。例如;
http://www.mysqltutorial.org/mysql-foreign-key/
举个例子:
这些线路:
将people表的id字段引用到phone numbers表的people\u id表。