您的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
)
答案 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
)
并且没有必要两次添加密钥