2016-02-03 55 views
0

您的SQL語法錯誤;檢查手冊中 對應喲你的MySQL服務器版本使用 附近 '' 學生 '(' subject_id ')ON UPDATE CASCADE ON DELETE CASCADE 外鍵(subje' 在行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

你必須刪除單引號以防萬一列名和表名:

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 
) 

而且也沒有必要添加鍵兩次