FK on a single column referencing a column from composite PK

后端 未结 2 1874
你的背包
你的背包 2020-12-22 09:15

Not able to create /find the logic to apply FK on a column in child table referencing a column from composite PK of parent table.

create table product(prod_i         


        
2条回答
  •  情歌与酒
    2020-12-22 10:11

    You can't.

    As the error says there's no matching primary key for that column list; you must have one. You have three options:

    1. Remove PROD_NAME from the primary key of PRODUCT. On the face of it this seems like the logical solution, if this is not required in order to make the primary key unique.

    2. Add PROD_NAME to the PURCHASE table.

    3. Create a unique index on PURCHASE.PROD_ID. This seems excessive if it would be a primary key candidate anyway.

提交回复
热议问题