我想使用mysql将表中的值复制到另一个表中,同时通过第三个表循环来设置特定值第二。mysql将数据库1中的数据库行多次复制到新数据库2,循环访问数据库3
表1被调用的国家,与结构和数据:
countries +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + countries_id + countries_name + countries_iso_code_2 + countries_iso_code_3 + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 + Belgium + BE + BEL + + 2 + Netherlands + NL + NLD + + 3 + Germany + DE + DEU + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
中的行countries_id和countries_name需要被复制到表countries_name。对于来自表语言的每个language_id。 表2
countries_name +++++++++++++++++++++++++++++++++++++++++++++++ + countries_id + language_id + countries_name + +++++++++++++++++++++++++++++++++++++++++++++++ + 1 + 1 + Belgium + + 2 + 1 + Netherlands + + 3 + 1 + Germany + + 1 + 3 + Belgium + + 2 + 3 + Netherlands + + 3 + 3 + Germany + + 1 + 4 + Belgium + + 2 + 4 + Netherlands + + 3 + 4 + Germany + +++++++++++++++++++++++++++++++++++++++++++++++
表3
languages +++++++++++++++++++++++++++++++++ + languages_id + name + code + +++++++++++++++++++++++++++++++++ + 1 + English + en + + 3 + Dutch + nl + + 4 + German + de + +++++++++++++++++++++++++++++++++
我知道如何为单次做到这一点,但并不适用于多个。
CREATE TABLE countries_name (
countries_id int(11) NOT NULL,
language_id int(11) NOT NULL DEFAULT 1,
countries_name varchar(64) NOT NULL,
UNIQUE countries (countries_id, language_id),
KEY idx_countries_name_zen (countries_name)
) ENGINE=MyISAM;
INSERT INTO countries_name (countries_id, countries_name)
SELECT c.countries_id, c.countries_name
FROM countries c;
所以,P浏览你的代码,你是如何做到这一点的? – Alex
加入单程的代码 – Zen4All