-1

错误图片

对这些语法错误有任何想法吗?与 FOREIGN KEY 语法有关?不知道!我删除了 ENGINE=INNODB; 行,但它仍然无法正常工作。

DROP TABLE IF EXISTS Marriage;
CREATE TABLE Marriage (
    marriageID int NOT NULL,
    PRIMARY KEY(marriageID),
    date DATE,
    place varchar(100)
);

前一个工作正常——真正的麻烦从下一个的外键开始:

DROP TABLE IF EXISTS MarriagePerson;
CREATE TABLE MarriagePerson (
    marriagePersonID int NOT NULL,
    marriageID int,
    personID int,
    PRIMARY KEY(marriagePersonID),  
    FOREIGN KEY marriageID REFERENCES Marriage(marriageID),
    FOREIGN KEY personID REFERENCES Person(personID)
);

DROP TABLE IF EXISTS Person;
CREATE TABLE Person (
     personID int NOT NULL,
     PRIMARY KEY(personID),
     firstName varchar(100),
     lastName varchar(100),
     gender  ENUM(male, female, nonBinary),
     birthDate DATE,
     birthPlace varchar(100),
     deathDate DATE,
     deathPlace varchar(100),
     causeOfDeath varchar(100),
     note varchar(1000)
) ENGINE=InnoDB;

DROP TABLE IF EXISTS Parent;
CREATE TABLE Parent (
    parentID int NOT NULL,
    PRIMARY KEY(parentID),
    FOREIGN KEY personID int,
    FOREIGN KEY parentPersonID int,
    relationship ENUM(sperm, egg)
) ENGINE=InnoDB;
4

1 回答 1

1

如果您按照与发布的顺序相同的顺序运行它,

在第二个查询中,您有:

FOREIGN KEY personID REFERENCES Person(personID)

尚未创建。Person 表在下一个查询中创建。

于 2017-02-28T06:36:52.217 回答