2015-06-03 164 views
0

我不斷收到1064錯誤,當我運行下面的查詢,但我不明白什麼是錯的:2個外鍵創建表時MySQL的語法錯誤主鍵

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 

感謝幫助。

+6

'group'是一個保留字,你需要反引號''它。 –

+0

就是這樣。可以相信這很簡單。謝謝。 – hash004

回答

2

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