我正在建立一个数据库来存放我的电影信息,所有电影都有不止一种类型,所以我试图通过链接表解决许多问题。我无法将链接表填充到我的电影和流派表中。该表是Movie_Genre
表,GenreID
和MovieID
都是该表的复合主键。每个部分(GenreID和MovieID)也是不同表的外键。我在使用其他表中的正确值填充此表时遇到问题。这是我的测试脚本。
Create Database Test;
Use Test;
Create Table Movies ( MovieID INT AUTO_INCREMENT Primary key, TiTel
Varchar(255) ) AUTO_INCREMENT=100;
Insert into Movies VALUES (TiTel, 'HellBoy'), (TiTel, 'Horrible
Bosses');
Create Table Genre (GenreID INT Auto_increment Primary key, Genre
VARCHAR(10));
Insert Into Genre Values (Genre,'Action'), (Genre,'Adventure'),
(Genre,'Si-Fi'), (Genre,'Horrer'), (Genre,'Fantacey'),
(Genre,'Thriller'), (Genre,'Comedy'), (Genre,'Crime');
Create Table Movie_Genre ( MovieID INT , GenreID INT, CONSTRAINT
FOREIGN KEY (MovieID) REFERENCES Movies(MovieID), CONSTRAINT FOREIGN
KEY (GenreID) REFERENCES Genre(GenreID), Primary key
(MovieID,GenreID));
Insert into Movie_Genre Value( MovieID = Movies(MovieID)),
(GenreID = Genre(GenreID));