【问题标题】:What does the message mean and how do i fix my code?该消息是什么意思,我该如何修复我的代码?
【发布时间】:2016-02-03 09:15:36
【问题描述】:

您的 SQL 语法有错误;检查手册 与您的 MySQL 服务器版本相对应,以便使用正确的语法 靠近''students'('subject_id') ON UPDATE CASCADE ON DELETE CASCADE FOREIGN KEY(第 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 
)

【问题讨论】:

    标签: mysql foreign-keys scientific-computing


    【解决方案1】:

    您必须删除列和表名周围的单引号:

    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 
    )
    

    而且也不需要两次添加密钥

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-14
      • 2016-03-05
      • 2014-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-15
      相关资源
      最近更新 更多