MySQL 使用 2 个外键作为主键创建 table 时出现语法错误
MySQL syntax error when creating a table with 2 foreign keys as primary key
当我 运行 以下查询时,我一直收到 1064 错误,但我不明白它有什么问题:
CREATE TABLE hashmkb_mangatracker.group_release
(
group_id int NOT NULL,
release_id int NOT NULL,
PRIMARY KEY (group_id, release_id),
UNIQUE INDEX (release_id, group_id),
FOREIGN KEY (group_id) REFERENCES group(id),
FOREIGN KEY (release_id) REFERENCES release(id)
) ENGINE=INNODB;
错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group(id),
FOREIGN KEY (release_id) REFERENCES release(id)
) ENGINE=INNODB' at line 7
感谢您的帮助。
GROUP 是 MySql 中的保留关键字。
RELEASE 也是如此。
您将不得不像这样在周围添加反引号:
CREATE TABLE hashmkb_mangatracker.group_release
(
group_id int NOT NULL,
release_id int NOT NULL,
PRIMARY KEY (group_id, release_id),
UNIQUE INDEX (release_id, group_id),
FOREIGN KEY (group_id) REFERENCES `group`(id),
FOREIGN KEY (release_id) REFERENCES `release`(id)
) ENGINE=INNODB;
这里是所有保留字的列表:http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html
当我 运行 以下查询时,我一直收到 1064 错误,但我不明白它有什么问题:
CREATE TABLE hashmkb_mangatracker.group_release
(
group_id int NOT NULL,
release_id int NOT NULL,
PRIMARY KEY (group_id, release_id),
UNIQUE INDEX (release_id, group_id),
FOREIGN KEY (group_id) REFERENCES group(id),
FOREIGN KEY (release_id) REFERENCES release(id)
) ENGINE=INNODB;
错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group(id),
FOREIGN KEY (release_id) REFERENCES release(id)
) ENGINE=INNODB' at line 7
感谢您的帮助。
GROUP 是 MySql 中的保留关键字。 RELEASE 也是如此。 您将不得不像这样在周围添加反引号:
CREATE TABLE hashmkb_mangatracker.group_release
(
group_id int NOT NULL,
release_id int NOT NULL,
PRIMARY KEY (group_id, release_id),
UNIQUE INDEX (release_id, group_id),
FOREIGN KEY (group_id) REFERENCES `group`(id),
FOREIGN KEY (release_id) REFERENCES `release`(id)
) ENGINE=INNODB;
这里是所有保留字的列表:http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html