我正在完成我的第一份家庭作业,但我无法正常工作。表格电影和明星的工作完全正常,但是当我尝试创建表格角色时,它会给我这个错误:ORA-02270:此列列表没有匹配的唯一键或主键
create table movie(id integer,
title varchar(50),
rating varchar(10),
genre varchar(15),
budget integer,
unique(id,title),
constraint moviekey primary key(id));
create table star(id integer,
name varchar(30),
birth_year integer,
gender varchar(10),
salary integer,
primary key(id,name),
constraint fk_mov_star foreign key (id) references movie(id) on delete cascade);
create table role(m_id integer,
s_id integer,
character_name varchar(40),
primary key(m_id,s_id,character_name),
constraint fk_mid_rol foreign key (m_id) references movie(id) on delete cascade,
constraint fk_sid_rol foreign key (s_id) references star(id));
答案 0 :(得分:1)
原因:“star(id)”是表星的外键,实际上是指“movie(id)”。
溶液: 将星号(id)设为主键;从星号中删除外键;
create table movie(id integer,
title varchar(50),
rating varchar(10),
genre varchar(15),
budget integer,
unique(id,title),
constraint moviekey primary key(id));
create table star(id integer,
name varchar(30),
birth_year integer,
gender varchar(10),
salary integer,
primary key(id) );
create table role(m_id integer,
s_id integer,
character_name varchar(40),
primary key(m_id,s_id,character_name),
constraint fk_mid_rol foreign key (m_id) references movie(id) on delete cascade,
constraint fk_sid_rol foreign key (s_id) references star(id));