CREATE TABLE电影资料库的MySQL问题

时间:2018-12-07 20:19:00

标签: mysql

我试图用多个外键创建一个引用其他父表的表。我的其中一个外键已被接受'fk_film_id',但是第二个不是由于语法错误引起的。我该如何通过?

我的桌子的身体在下面:

create table `Actor_Role` (
`Actor_Role_id` INT AUTO_INCREMENT,
`Actor_Role` VARCHAR(20) NOT NULL,
`Character_Name` VARCHAR(50) NOT NULL,
`Alias_Name` VARCHAR(50) NOT NULL,
 PRIMARY KEY (`Actor_Role_id`)
 );

create table `Actor` (
`Actor_id` INT AUTO_INCREMENT,
`First_Name` VARCHAR(20) NOT NULL,
`Last_Name` VARCHAR(50) NOT NULL,
`Date_of_Birth` DATE NOT NULL,
`Nationality` VARCHAR(20) NOT NULL,
`Gender` VARCHAR(10) NOT NULL,
`Residence` VARCHAR(20) NOT NULL,
PRIMARY KEY (`Actor_id`)
);

create table `Film` (
`Film_id` INT AUTO_INCREMENT,
`Title` VARCHAR(50) NOT NULL,
`Release_Date` DATE NOT NULL,
`Running_Time` INT NOT NULL,
`Budget` BIGINT NOT NULL,
`Box_Office` BIGINT NOT NULL,
`Rating` INT NOT NULL,
`Language` VARCHAR(10) NOT NULL,
PRIMARY KEY (`Film_id`)
);

create table `Film_Staff` (
`Staff_id` INT AUTO_INCREMENT,
`First_Name` VARCHAR(20) NOT NULL,
`Last_Name` VARCHAR(50) NOT NULL,
`Nationality` VARCHAR(20) NOT NULL,
PRIMARY KEY (`Staff_id`)
);

create table `Staff_Role` (
`Staff_Role_id` INT AUTO_INCREMENT,
`Staff_Role` VARCHAR(20) NOT NULL,
PRIMARY KEY (`Staff_Role_id`)
);

create table `Infinity_Stones` (
`Stone_id` INT AUTO_INCREMENT,
`Colour` VARCHAR(10) NOT NULL,
`Power` VARCHAR(10) NOT NULL,
PRIMARY KEY (`Stone_id`)
);

我要制作的表如下所示:

CREATE TABLE Film_Staff_Role(
    -> `Film_id` INT NOT NULL,
    -> `Role_id` INT NOT NULL,
    -> `Staff_id` INT NOT NULL,
    -> FOREIGN KEY fk_film_id(Film_id)
    ->  REFERENCES film(Film_id)
    -> ON UPDATE CASCADE
    -> ON DELETE RESTRICT
    ->  FOREIGN KEY fk_Role_id(Role_id)
    -> REFERENCES Staff_Role(Staff_Role_id)
    -> ON UPDATE CASCADE
    -> ON DELETE RESTRICT
    ->  FOREIGN KEY fk_Staff_id(Staff_id)
    -> REFERENCES Film_Staff(Staff_id)
    -> ON UPDATE CASCADE
    -> ON DELETE RESTRICT
    -> )ENGINE=InnoDB;

但是,当我尝试执行时收到以下问题:

  

错误1064(42000):您的SQL语法有错误;检查   与您的MySQL服务器版本相对应的手册   在'FOREIGN KEY fk_Staff_Role_id(Staff_Role_id)附近使用的语法   参考Staff_Role(Staff_Role_id'在第9行

如何克服?

0 个答案:

没有答案