0
我有EMP1和EMP2表Oracle中有两列的主键?
EMP1:
emp_1 | emp_2
1 | 2
3 | 4
5 | 6
EMP2:
emp
1
2
3
6
我试图设置主键表EMP1和外键EMP2。
我的代码:
主键:
alter table emp1 add primary key(emp_1,emp_2);
对于外键:
alter table emp2
add foreign key (emp)
references a_t1(emp_1,emp_2);
错误:
Error report -
SQL Error: ORA-02256: number of referencing columns must match referenced columns
02256. 00000 - "number of referencing columns must match referenced columns"
*Cause: The number of columns in the foreign-key referencing list is not
equal to the number of columns in the referenced list.
*Action: Make sure that the referencing columns match the referenced
columns.
请帮助我解决这个错误,设置主键。
您试图将一个外键从一个字段添加到两个字段;您必须确定表EMP2中的值是否必须与表EMP1中的emp_1或emp_2列中的记录相匹配。 – Aleksej
您不能让FK指向复合PK的一部分,或两个单独的密钥(PK或UK)中的任意一个。例如,如果emp1中的行具有值(7,8)和值(8,9),并且需要emp2中的值为(8),那么您会发生什么?父母中哪一行是指的? –
是的,我明白了。我试图制作一个复合主键。 – user5505661