消息是什么意思,我如何修复我的代码?

时间:2016-02-03 09:15:37

标签: mysql foreign-keys scientific-computing

  

您的SQL语法有错误;检查手册   与您的MySQL服务器版本对应,以便使用正确的语法   在''students'('subject_id')附近,在DELETE CASCADE上更新CASCADE   外键(第8行的主题'

CREATE TABLE Entries
 (
entry_id int NOT NULL,
subject_id int NOT NULL,
student_id int NOT NULL,
exam_date int,
PRIMARY KEY (subject_id),
FOREIGN KEY (student_id) REFERENCES 'students'('student_id')
ON UPDATE CASCADE ON DELETE CASCADE 
FOREIGN KEY (subject_id) REFERENCES 'subjects'('subject_id')
ON UPDATE CASCADE ON DELETE CASCADE 
)

1 个答案:

答案 0 :(得分:0)

您必须删除单引号arround列和表名:

CREATE TABLE Entries
 (
entry_id int NOT NULL,
subject_id int NOT NULL,
student_id int NOT NULL,
exam_date int,
PRIMARY KEY (subject_id),
FOREIGN KEY (student_id) REFERENCES students(student_id)
ON UPDATE CASCADE ON DELETE CASCADE 
)

并且没有必要两次添加密钥