我有这些表:引用了一个外键是与父表的另一个关键主键
: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中的同名。 非常感谢。 –