0
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,我只是在沒有他們的情況下練習。提前致謝! :)MySQL,不能創建外鍵
什麼是錯誤? – Mihai
這個人的FK是錯誤的,你應該同時對名字和第二個名字進行單獨的約束,而不是單獨的約束。 –
非常感謝你Matteo Tassinari,它現在工作!哦,現在我會知道:)謝謝:) –