创建相关表SQL

时间:2018-01-26 21:45:50

标签: mysql sql foreign-keys create-table

我有三个表患者疾病提供者。所有三个表都可以通过patient_id和disease_name关联。我知道你需要:CONSTRAINT,FOREIGN KEY和REFERENCES来完成所有三个表的关系。我在第7行收到错误有人能告诉我我做错了什么吗?我无法发布问题的图片,但这里是错误: 错误 SQL查询:

MySQL说:文档

  

#1064 - 您的SQL语法出错;检查与您的MySQL服务器版本相对应的手册,以便在' patient_id')附近使用正确的语法

CREATE TABLE patient(
    patient_id INT (3) NOT NULL AUTO_INCREMENT,
    place VARCHAR (20) NOT NULL,
    profession VARCHAR (30)NOT NULL,
    age INT (11),
    PRIMARY KEY (patient_id),
    CONSTRAINT patient_info FOREIGN KEY (patient_id) REFERENCES patient ('patient_id')
);
CREATE TABLE disease (
    patient_id INT (3) NOT NULL AUTO_INCREMENT,
    disease_name VARCHAR (20) NOT NULL,
    duration_of_stay INT(11),
    CONSTRAINT patient FOREIGN KEY(patient_id) REFERENCES patient ('patient_id'),
    CONSTRAINT disease_info FOREIGN KEY(disease_name) REFERENCES disease ('disease_name') 
);

CREATE TABLE provider(
    disease_id INT (3) NOT NULL AUTO_INCREMENT,
    disease_name VARCHAR (20) NOT NULL,
    doctor_name VARCHAR (20) NOT NULL,
    CONSTRAINT disease_info FOREIGN KEY (disease_name) REFERENCES disease ('disease_name')
);

0 个答案:

没有答案