添加外键约束时出现 MYSQL 错误 #1064
我不断收到此 sql 错误
"#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 'Option (OptionId)' at line 1"
当我尝试将外键添加到问题表中的 OptionId 字段到选项字段中的 OptionId(pk) 字段时, 。我不明白为什么我不断收到错误,因为我不明白它出了什么问题。
下面是使用 ALTER TABLE 的外键约束:
ALTER TABLE Question ADD CONSTRAINT FK_OptionId FOREIGN KEY (OptionId) REFERENCES Option (OptionId)
表名和语法是正确的,我通过双重检查确保了这一点。
为什么它不起作用?
I keep getting this sql 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 'Option (OptionId)' at line 1"
when I try and add a foreign key to the OptionId field from the Question Table to the OptionId(pk) field in the Option field. I don't get wy I keep getting the error because I don't see what is wrong with it.
Below is the foreign key constraint using ALTER TABLE:
ALTER TABLE Question ADD CONSTRAINT FK_OptionId FOREIGN KEY (OptionId) REFERENCES Option (OptionId)
Table names and syntax are correct, I made sure by double checking.
Why is it not working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
option
是一个保留字 在 MySQL 中并且必须用反引号括起来。option
is a reserved word in MySQL and must be surrounded by backticks.