2017-09-29 94 views
0

我正在處理我的第一個家庭作業,並且無法正常工作。該表的電影和明星的工作完全正常,但是當我嘗試創建它給了我這個錯誤表的作用:ORA-02270:不匹配此列列表唯一或主鍵sql: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)); 

回答

1

原因:「星(id)「是表星的外鍵,它實際上是指」電影(id)「。

解決方案: 將star(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)); 
相關問題