通过 My-SQL Workbench 在 SQL 中添加外键给出错误 1064
Add Foreign Key in SQL by My-SQL Workbench gives Error 1064
我想将外键添加到名为“地址”的 table。
ALTER TABLE `students1`.`address`
ADD CONSTRAINT `id_country`
FOREIGN KEY ()
REFERENCES `students1`.`country` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION;
此请求由 MySQLWorkbench 自动生成。
但是得到这个错误
ERROR 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 ')
REFERENCES `students1`.`country` ()
ON DELETE NO ACTION
ON UPDATE NO ACT' at line 3
如何解决这个问题?
我不知道你的两个表是否有相同的列id_country
。
但这种情况下的语法是:
ALTER TABLE `students1`.`address`
ADD CONSTRAINT
FOREIGN KEY (`id_country`)
REFERENCES `students1`.`country`(`id_country`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;
我想将外键添加到名为“地址”的 table。
ALTER TABLE `students1`.`address`
ADD CONSTRAINT `id_country`
FOREIGN KEY ()
REFERENCES `students1`.`country` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION;
此请求由 MySQLWorkbench 自动生成。 但是得到这个错误
ERROR 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 ')
REFERENCES `students1`.`country` ()
ON DELETE NO ACTION
ON UPDATE NO ACT' at line 3
如何解决这个问题?
我不知道你的两个表是否有相同的列id_country
。
但这种情况下的语法是:
ALTER TABLE `students1`.`address`
ADD CONSTRAINT
FOREIGN KEY (`id_country`)
REFERENCES `students1`.`country`(`id_country`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;