2013-12-07 32 views
0

我有一個問題添加一個外鍵到我的表在SQL

create table REALESTATE (
reale_id  integer, 
agents_id  integer not null, 
listing_id  integer not null, 
primary key (reale_id) 
); 

* 表創建 *

create table AGENTS (
agents_id integer, 
agents_name char(10) not null, 
agents_lname char(20) not null, 
listing_id integer, 
customer_id integer, 
reale_id integer, 
primary key (agents_id), 
foreign key (customer_id) references AGENT (customer_id), 
foreign key (reale_id) references REALESTATE (reale_id) 
); 

行錯誤9: ORA-00942:表或視圖不存在

create table CUSTOMER (
customer_id  integer, 
customer_name char(6) not null, 
customer_lname char(15) not null, 
agents_id  integer, 
primary key (customer_id), 
foreign key (agents_id) references AGENTS (agents_id) 
); 

錯誤在第7行:ORA-00942:表或視圖不存在

回答

0

在代理的create table中,您有此行。

foreign key (customer_id) references AGENT (customer_id), 

但是,表代理不存在。此時只有表房地產存在。這意味着表代理沒有被創建,導致表客戶的問題。

0

表名稱是AGENTS不AGENT。

變化foreign key (customer_id) references AGENT (customer_id),foreign key (customer_id) references AGENTS (customer_id),

0

AGENTS沒有創建,因爲它引用了一個名爲AGENT表(見失蹤S),它不存在。由於AGENTS的創建失敗,因此它無法創建CUSTOMERS,因爲它引用了AGENTS以及未創建(由於之前的錯誤)。

在表AGENTS中:使用references AGENTS (customer_id)