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中出现错误。我不想知道为什么我在数据库里不使用任何身份证明,我只是在没有它们的情况下练习。谢谢!)
发布于 2013-09-29 19:18:57
"8.关系中的一个字段是组合(复合)键的一部分,没有它自己的单独索引。尽管字段有一个索引作为复合键的一部分,但您必须为该键字段创建单独的索引,以便在约束中使用它。
请看这篇老文章here。
https://stackoverflow.com/questions/19081189
复制相似问题