对这些语法错误有任何想法吗?与 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;