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映射表。
謝謝。