SQL>
SQL>
SQL>
SQL>
SQL> create table a(id number,name varchar2(32));
Table created.
SQL> create table b(pid number,name varchar2(32));
Table created.
SQL> alter table b add constraint FK_B foreign key (pid) references a (ID) ;
alter table b add constraint FK_B foreign key (pid) references a (ID)
*
ERROR at line 1:
ORA-02270: 此列列表的唯一关键字或主键不匹配
SQL> alter table a add constraints pk_a primary key(id);
Table altered.
SQL> alter table b add constraint FK_B foreign key (pid) references a (ID) ;
Table altered.
SQL>
1 外键是针对从表的
2 主表一定要有主键,否则在从表中建不了外键