Oracle 引用复合PK中的列的单个列上的FK
无法创建/找到对子表中引用父表复合主键列的列应用FK的逻辑Oracle 引用复合PK中的列的单个列上的FK,oracle,database-design,foreign-keys,Oracle,Database Design,Foreign Keys,无法创建/找到对子表中引用父表复合主键列的列应用FK的逻辑 create table product(prod_id number, prod_name varchar2(20), price number, constraint PK12 primary key(prod_id,prod_name)); ERROR at line 1: ORA-02270: no matching unique or primary key for this column-list
create table product(prod_id number,
prod_name varchar2(20),
price number,
constraint PK12 primary key(prod_id,prod_name));
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
表已创建
create table purchase(prod_id number,
purchase_price number,
constraint FK12 foreign key(prod_id) references product(prod_id));
create table purchase(prod_id number,
purchase_price number,
constraint FK12 foreign key(prod_id) references product(prod_id))
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
金尔迪建议我如何将这种逻辑结合起来
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
谢谢。我怀疑这不是Oracle独有的。考虑到引用表中有一个复合主键,这意味着组成复合键的列中只有一列不足以唯一标识该表中的记录。因此,在一对多的外键关系中,不可能只引用主键的一列(例如,被引用表中的一条记录可以在引用表中有多条记录——带有FK的记录)。然而,如果要建立的关系是多对多的,这可能是可能的
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
HTH.我怀疑这不是Oracle独有的。考虑到引用表中有一个复合主键,这意味着组成复合键的列中只有一列不足以唯一标识该表中的记录。因此,在一对多的外键关系中,不可能只引用主键的一列(例如,被引用表中的一条记录可以在引用表中有多条记录——带有FK的记录)。然而,如果要建立的关系是多对多的,这可能是可能的
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
嗯。你不能
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
正如错误所说,该列列表没有匹配的主键;你必须有一个。您有三种选择:
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
你不能
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
正如错误所说,该列列表没有匹配的主键;你必须有一个。您有三种选择:
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
我同意。我认为PROD_ID听起来像是主键,也许PROD_NAME是唯一的(业务)键。我同意。我认为PROD_ID听起来像是主键,也许PROD_名称是唯一的(业务)键。