加入表错误

时间:2012-11-07 05:03:37

标签: sql oracle jointable

我创建的Table1具有复合键(column1,column2,column3)

CONSTRAINT table_PK PRIMARY KEY (column1,column2,column3)

表2有复合键(column1,column4)

CONSTRAINT table2_FK FOREIGN KEY (column1)
  REFERENCES table1 (column1)
CONSTRAINT table2_column4_FK FOREIGN KEY (column4)
  REFERENCES table3 (column4)

但是我无法将表2连接到表1.在2个表之间,唯一的引用列应该只是column1

但是我收到了一个错误:

SQL Error: 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

我已经尝试检查约束,一切似乎都正确。

当我尝试使用界面来创建表时,它也没有用。

The number of FK columns (2) does not equal to the number of referenced columns (3)

从我看到的,他们要求我有相同数量的列来引用另一个表。但是我不认为这是必要的。它应该只需要1列吗?如果我错了,请纠正我。

1 个答案:

答案 0 :(得分:3)

我认为您的外键约束需要引用table_PK上构成主键的所有三列。

由于您基本上是根据三列中每一列(即每个tuple)的值组合确定每个主键是唯一的,因此外键约束需要引用所有三列为了确定哪个唯一记录/元组与table_PK中的密钥相关联。