2017-10-04 53 views
0

我無法增加超過1個外鍵,我的表,我得到的錯誤:如何有一個以上的外鍵?

"Error report - 
ORA-02270: no matching unique or primary key for this column-list 
02270. 00000 - "no matching unique or primary key for this column-list" 
*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement 
      gives a column-list for which there is no matching unique or primary 
      key constraint in the referenced table. 
*Action: Find the correct column names using the ALL_CONS_COLUMNS 
      catalog view" 

我試圖使該表沒有第三外鍵和它的工作,所以我覺得它的東西做與最後的關鍵,但真的不知道。 (我把空間在SQL之間,使其更易於閱讀。)

CREATE TABLE ORDER(
ORDERID CHAR(4) NOT NULL, 
HOUSETYPE CHAR(2), 
CHAIR CHAR(2), 
PERSON CHAR(2), 
PAYDAY DATE, 
MENUPRICE NUMBER(4,2), 
CONSTRAINT CONFERENCESESSION_PK PRIMARY KEY(ORDERID), 
CONSTRAINT CONFERENCESESSION_FK1 FOREIGN KEY(HOUSETYPE) REFERENCES 
    HOUSE(HOUSETYPE), 
CONSTRAINT CONFERENCESESSION_FK2 FOREIGN KEY(PAYDAY) REFERENCES PERSON(PAYDAY), 
CONSTRAINT CONFERENCESESSION_FK3 FOREIGN KEY(MENUPRICE) REFERENCES 
    MENU(MENUPRICE) 
); 
+0

請閱讀[我如何格式化用降價或HTML我的帖子?](https://stackoverflow.com/help/formatting)現在,你的職位是不可讀的混亂,它是不太可能在它要回答的是目前的形式。 – waka

+0

是否每個FK引用參考表中的PK或UNIQUE約束? – jarlh

+0

錯誤消息是相當清楚的。 – APC

回答

1

外鍵必須引用另一個表的主鍵,我的猜測是,一些你的外鍵不引用的主鍵另一張桌子。

A FOREIGN KEY is a key used to link two tables together.

A FOREIGN KEY is a field (or collection of fields) in one table that refers to the PRIMARY KEY in another table.

The table containing the foreign key is called the child table, and the table containing the candidate key is called the referenced or parent table.

https://www.w3schools.com/sql/sql_foreignkey.asp

0

外鍵必須引用另一個表的主鍵,以便確保你正在做的與主鍵的名稱權。例如:

CONSTRAINT CONFERENCESESSION_FK2 FOREIGN KEY(PAYDAY) REFERENCES PERSON(PAYDAY) 

確保在表PERSON你有PRIMARY KEY與名PAYDAY

相關問題