create table movie(
movieTitle varchar(40)
not null
, yearReleased year
check (not year > year(current_date))
, movieLength int(3)
null
, constraint coPKmovie
primary key (movieTitle, yearReleased)
);
create table person(
personName varchar(40)
not null
, secondName varchar(40)
not null
, dateOfBirth datetime
not null
, yearCareerStarted year
not null
check (not year > year(current_date))
, bornCountry char(03)
not null
, constraint coPKperson
primary key (personName, secondName)
);
create table participant(
partPersonName varchar(40)
not null
, partSecondName varchar(40)
not null
, movieTitle varchar(40)
not null
, jobTitle varchar(30)
not null
, constraint coPKpart
primary key (partPersonName, partSecondName, movieTitle, jobTitle)
);
alter table participant
add constraint partFKname foreign key (partPersonName)
references person (personName)
, add constraint partFKSecond foreign key (partSecondName)
references person (secondName)
, add constraint partFKmovie foreign key (movieTitle)
references movie (movieTitle)
on delete cascade
on update cascade;
有人可以解释为什么我想从表参与者 partSecondName 到表 person , secondName 创建外键时总是出错。我不想听为什么我不在我的数据库中使用任何 id,我只是在没有它们的情况下练习。提前致谢!:)