SQL无法添加外键约束

时间:2016-10-01 18:04:38

标签: mysql sql

我有这个SQL代码,在尝试创建外键时不断出错。我不知道我在做什么。

CREATE TABLE IF NOT EXISTS `myDatabaseOne`.`Teams` (
    `idTeams` INT NOT NULL COMMENT '    ',
    `Semester` VARCHAR(45) NOT NULL,
    `Year` YEAR NOT NULL,
    `Captain` INT(5) NOT NULL,
    `Sport` INT NOT NULL,
    PRIMARY KEY (`idTeams`),
    INDEX `fk_Teams_Students_idx` (`Captain` ASC),
    INDEX `fk_Teams_Sports1_idx` (`Sport` ASC),
    CONSTRAINT `fk_Teams_Students`
      FOREIGN KEY (`Captain`)
      REFERENCES `myDatabaseOne`.`Students` (`idStudents`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_Teams_Sports1`
      FOREIGN KEY (`Sport`)
      REFERENCES `myDatabaseOne`.`Sports` (`idSports`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)

0 个答案:

没有答案