我有這些表:引用了一個外鍵是與父表的另一個關鍵主鍵
:ORA-02270: no matching unique or primary key for this column-list
create table t_table(t1 int, constraint tprim primary key(t1));
create table parent_table(t1 int, p1 int, p2 int, constraint pprim primary key(t1, p1));
create table child_table(t1 int, c1 int, p1 int, constraint cprim primary key(t1, c1), constraint fchild foreign key (p1) references parent_table(p1));
我創建第二個表時出現此錯誤
p1
在parent_table中不是唯一的,所以我不能讓它唯一的解決問題。
在這種情況下如何說p1
是引用parent_table(p1)的child_table中的外鍵?
在此先感謝。
請,你是怎麼用'也許你想要做的是包括在國外關鍵child_table T1?'的意思是,你在同一個意思外鍵約束(使用p1)如果兩個鍵屬於不同的表時,情況如何? –
@ youzking - 他們不屬於不同的表。 (t1,p1)在parent_table中的child_table引用(t1,p1)中 - 即使單獨的t1和p1都不是PK到parent_table。該對是主鍵,並且您可以從child_table引用。 – mathguy
哦,當然,因爲t1是t_table中的第一個主鍵,我想它屬於t_table,我忘記它只是在child_table中的同名。 非常感謝。 –