mysql外键

h4cxqtbf  于 2021-06-17  发布在  Mysql
关注(0)|答案(0)|浏览(121)

我试图在movie\u copies表中创建外键,该表引用movie\u details和customer\u details表中的主键,但似乎对我不起作用,而且出现的语法错误似乎与索引有关。

-- -----------------------------------------------------
-- Table `Movie_Renting`.`Movie_Details`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Movie_Renting`.`Movie_Details` (
  `Movie_ID` VARCHAR(20) NOT NULL,
  `Movie_Title` VARCHAR(256) NOT NULL,
  `Release_Date` DATE NOT NULL,
  `Run_Time` VARCHAR(10) NOT NULL,
  `Genre` VARCHAR(20) NOT NULL,
  `Rating` INT NOT NULL,
  `Number_of_Copies` INT NOT NULL,
  PRIMARY KEY (`Movie_ID`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `Movie_Renting`.`Customer_Details`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Movie_Renting`.`Customer_Details` (
  `Customer_ID` VARCHAR(10) NOT NULL,
  `Customer_Name` VARCHAR(800) NOT NULL,
  `Address_Line_One` VARCHAR(100) NOT NULL,
  `Address_Line_Two` VARCHAR(100) NULL,
  `Town` VARCHAR(90) NOT NULL,
  `Post_Code` VARCHAR(8) NOT NULL,
  `Contact_Number` VARCHAR(12) NOT NULL,
  `Email_Address` VARCHAR(345) NOT NULL,
  PRIMARY KEY (`Customer_ID`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `Movie_Renting`.`Movie_Copies`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Movie_Renting`.`Movie_Copies` (
  `Copy_ID` VARCHAR(10) NOT NULL,
  `Movie_ID` VARCHAR(10) NOT NULL,
  `Platform` VARCHAR(20) NOT NULL,
  `Customer_ID` VARCHAR(45) NOT NULL,
  `Rent_Out` DATE NOT NULL,
  `Duration_Weeks` INT NOT NULL,
  `Return_Date` DATE NOT NULL,
  `Customer_Details_Customer_ID` VARCHAR(10) NOT NULL,
  PRIMARY KEY (`Copy_ID`),
  INDEX `fk_Movie_Copies_Movie_Details_idx` (`Movie_ID` ASC) VISIBLE,
  INDEX `fk_Movie_Copies_Customer_Details1_idx` (`Customer_ID` ASC) VISIBLE,
  CONSTRAINT `fk_Movie_Copies_Movie_Details`
    FOREIGN KEY (`Movie_ID`)
    REFERENCES `Movie_Renting`.`Movie_Details` (`Movie_ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Movie_Copies_Customer_Details1`
    FOREIGN KEY (`Customer_ID`)
    REFERENCES `Movie_Renting`.`Customer_Details` (`Customer_ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题