我列出了三个表格,分别是“学生”,“参与”和“学生注册”。 当我创建以下SQL来创建表和外键约束时。我使用的查询如下
CREATE TABLE IF NOT EXISTS `mydb`.`Student` (
`SID` INT NOT NULL,
`BIRTHDTE` DATE NULL,
`FNAMES` VARCHAR(255) NULL,
PRIMARY KEY (`SID`))
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `mydb`.`Engagement` (
`SID` INT NOT NULL,
`NUMHUS` INT NOT NULL,
`ACCESSPRG` VARCHAR(45) NULL,
`HIGHESTQUAL` VARCHAR(45) NULL,
PRIMARY KEY (`SID`, `NUMHUS`),
CONSTRAINT `FK_SID1111`
FOREIGN KEY (`SID`)
REFERENCES `mydb`.`Student` (`SID`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `mydb`.`StudentRegistration` (
`NUMHUS` INT NOT NULL,
`NUMREG` VARCHAR(45) NOT NULL,
`SID` INT NOT NULL,
INDEX `FK_SID_idx` (`SID` ASC),
CONSTRAINT `FK_NUMHUS`
FOREIGN KEY (`NUMHUS`)
REFERENCES `mydb`.`Engagement` (`NUMHUS`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `FK_SID`
FOREIGN KEY (`SID`)
REFERENCES `mydb`.`Engagement` (`SID`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
执行上述脚本时出现以下错误
1005-无法创建表
mydb
。studentregistration
(错误号:150“外键约束格式不正确”)(详细信息...)
我考虑了以下三种选择