我正在创建此数据库并立即开始使用外键,我无法放置外键MoviesParticipated.MovieName - MoviesData.MovieName
,看来我没有主键或候选键。
我的目标是能够回答以下问题:“ X演员参加过哪些电影”,“哪些演员参加了X电影”(除了显示电影,演员和系列数据,当然还包括每个季节的剧集) )。
-电影表
MoviesData (
MovieID int PK,
MovieName nvarchar(50),
MovieDescription text,
MovieYear nvarchar(4),
ParticipationID int);
-系列表
SeriesData (
SeriesID int PK,
SeriesName varchar(50),
SeriesDescription text,
SeriesCategory varchar(50),
SeriesYear varchar(4),
ParticipationId int );
-演员表
ActorsData (
ActorID int PK,
ActorName varchar(50),
ActorAge varchar(3),
ParticipationId int )
-SeasonsnEpisodes
SeasonsEpisodes (
SerieID int PK,
SerieSeasons int,
SerieEpisodes int)
-电影参加了
MoviesParticipated (
ParticipationId int PK
ActorID int
MovieID varchar(50));
-SeriesParticiped
SeriesParticipated (
ParticipationId int PK
ActorID int
SeriesID varchar(50))
当我尝试创建此外键时:
Alter table MoviesParticipated
add foreign key (MovieName) references MoviesData(MovieName);
出现此错误:
Msg 1776, Level 16, State 0, Line 1
There are no primary or candidate keys in the referenced table 'MoviesData' that match the referencing column list in the foreign key 'FK__MoviesPar__Movie__74AE54BC'.