0
我有一个关于sql关系概念的问题。我有一个简单的例子。 一个桌子人,国家和我想记录人的生活历史。协会最佳模式
CREATE TABLE person
(
person_id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT
);
CREATE TABLE country
(
country_id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT
);
解决方案一:
create table person_live_country
(
plc_id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
person_id INT UNSIGNED NOT NULL,
country_id INT UNSIGNED NOT NULL,
FOREIGN KEY (person_id) REFERENCES person (person_id),
FOREIGN KEY (country_id) REFERENCES country (country_id)
);
解决方法二:
create table person_live_country
(
person_id INT UNSIGNED NOT NULL,
country_id INT UNSIGNED NOT NULL,
PRIMARY KEY (person_id, country_id),
FOREIGN KEY (person_id) REFERENCES person (person_id),
FOREIGN KEY (country_id) REFERENCES country (country_id)
);
什么是最好的模式:概念,性能,便利性? 将来我想用JPA映射表。
谢谢。