Итак - у меня есть две таблицы, которые я пытаюсь связать: турнир и матч. Они могут быть изложены следующим образом:
tournament
-id (int)
-league (varchar)
-status (varchar)
-create_time (datetime)
-update_time (datetime)
match
-id (int)
-tournament_id (int)
-status (varchar)
-create_time (datetime)
-update_time (datetime)
Я пытаюсь добавить ограничение внешнего ключа в таблицу соответствий с помощью следующего SQL:
ALTER TABLE 'match' ADD CONSTRAINT
('FK_match_tournament') FOREIGN KEY
('tournament_id') REFERENCES
'tournament' ('id') ON DELETE CASCADE
ON UPDATE RESTRICT;
однако, я получаю следующее сообщение об ошибке от MySQL:
#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
''match' ADD CONSTRAINT ('FK_match_tournament') FOREIGN KEY ('tournament_id') REF'
at line 1
Я посмотрел синтаксис для добавления ограничений FK на веб-сайт MySQL, и все выглядит правильно для меня. Есть идеи?
Первое предложение (manuelpedrera):
ALTER TABLE `match` ADD CONSTRAINT ('FK_match_tournament') FOREIGN KEY ('tournament_id') REFERENCES `tournament` ('id') ON DELETE CASCADE ON UPDATE RESTRICT;
Результаты:
#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 '('FK_match_tournament') FOREIGN KEY ('tournament_id') REFERENCES `tournament` ('' at line 1