【发布时间】:2011-07-23 04:58:21
【问题描述】:
所以——我有两张表要关联:锦标赛和比赛。它们可以概括如下:
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
我在 MySQL 网站上查看了添加 FK 约束的语法,一切都对我来说是正确的。有什么想法吗?
第一个建议(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
【问题讨论】:
标签: php mysql sql yii constraints