我可以建议你另一种桌子设计。创建languages
表,并修改一个小country
表:添加lang_id
字段并创建外键 - FOREIGN KEY (lang_id) REFERENCES 语言 (id)。然后填充languages
和country
表格。
例如:
CREATE TABLE languages(
id VARCHAR(2) NOT NULL,
name VARCHAR(64) NOT NULL,
PRIMARY KEY (id)
) ENGINE = INNODB;
CREATE TABLE country(
id VARCHAR(2) NOT NULL,
lang_id VARCHAR(2) NOT NULL DEFAULT '',
name VARCHAR(64) NOT NULL,
PRIMARY KEY (id, lang_id),
CONSTRAINT FK_country_languages_id FOREIGN KEY (lang_id)
REFERENCES languages (id) ON DELETE RESTRICT ON UPDATE RESTRICT
)
ENGINE = INNODB;
-- Populate languages
INSERT INTO languages VALUES
('en', 'English'),
('de', 'German');
-- Populate names from 'en' table
INSERT INTO country SELECT id, 'en', name FROM country_en;
-- Populate names from 'de' table
INSERT INTO country SELECT id, 'de', name FROM country_de;
...您的链接中的表格在哪里country_en
和是什么。country_de