Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle 引用复合PK中的列的单个列上的FK_Oracle_Database Design_Foreign Keys - Fatal编程技术网

Oracle 引用复合PK中的列的单个列上的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

无法创建/找到对子表中引用父表复合主键列的列应用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 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
    
  • 在PURCHASE.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
    
  • 从产品的主键中删除产品名称。从表面上看,这似乎是合乎逻辑的解决方案,如果为了使主键唯一而不需要这样做的话

  • 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
    
  • 在PURCHASE.PROD_ID上创建一个唯一索引。如果它仍然是主键候选项,这似乎太过分了

  • ERROR at line 1:
    ORA-02270: no matching unique or primary key for this column-list
    

    我同意。我认为PROD_ID听起来像是主键,也许PROD_NAME是唯一的(业务)键。我同意。我认为PROD_ID听起来像是主键,也许PROD_名称是唯一的(业务)键。