SQL> desc pp; --父表
Name Type Nullable Default Comments
---- ------- -------- ------- --------
A INTEGER Y
B INTEGER Y
SQL> desc child;--子表
Name Type Nullable Default Comments
---- ------- -------- ------- --------
C INTEGER Y
D INTEGER Y
SQL> alter table child add constraint fk_d foreign key (c) references pp(b);
alter table child add constraint fk_d foreign key (c) references pp(b)
ORA-02270: 此列列表的唯一或主键不匹配
以上说明要建立外键时(在子表上),主表上面(补子表所引用的)一定要构建主键或唯一索引
SQL> alter table pp add constraint pk_a primary key(a);
Table altered
SQL> alter table child add constraint fk_d foreign key (c) references pp(a);
Table altered
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9240380/viewspace-664397/ ,如需转载,请注明出处,否则将追究法律责任。