SQL外键,无法设置外键约束

时间:2017-12-13 14:59:47

标签: mysql sql

CREATE TABLE students(
  student_id int(11) NOT NULL AUTO_INCREMENT,
  first_name varchar(255) NOT NULL,
  last_name varchar(255) NOT NULL,
  advisor_id int(11) DEFAULT NULL,
  PRIMARY KEY (student_id),
  KEY advisor_id (advisor_id),
  CONSTRAINT FOREIGN KEY (advisor_id) REFERENCES advisors (advisor_id)
);

1 个答案:

答案 0 :(得分:-1)

CONSTRAINT (advisor_id) FOREIGN KEY REFERENCES advisors (advisor_id)