ALTER TABLE Class_T (
ADD COLUMN 'hostId' INT,
ADD FOREIGN KEY ('hostId') REFERENCES Host_T ('hostId'));
我试图在Class_T表中添加一列,并使其成为另一个表中的主键。我正在使用phpmyadmin。
尝试运行此错误时,我一直收到此错误。
Error SQL query: ALTER TABLE Class_T ( ADD COLUMN 'hostId' INT,
ADD FOREIGN KEY ('hostId') REFERENCES Host_T ('hostId'))
MySQL said: Documentation #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
'( ADD COLUMN 'hostId' INT, ADD FOREIGN KEY ('hostId')
REFERENCES Host_T ('host' at line 1 –
有人知道我的代码有什么问题吗?
最佳答案
尝试卸下支架:
ALTER TABLE Class_T
ADD COLUMN 'hostId' INT,
ADD FOREIGN KEY ('hostId') REFERENCES Host_T ('hostId');
关于mysql - 包含外键约束的Alter语句,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24376936/