oracle - how to add a foreignkey to a composite primary key -
i have 2 tables: t_campagne_sms_repartition
, t_campagne_sms_execution
.
in t_campagne_sms_repartition
there 2 primary keys.
in t_campagne_sms_execution
there 1 primary key , 4 foreign keys.
how can add 4th foreign key cle_partition
of t_campagne_sms_execution
?
i have tried this:
alter table "t_campagne_sms_execution" add constraint fk_repartition foreign key("cle_repartition") references "t_campagne_sms_repartition"("cle_repartition");
but got error:
erreur commençant à la ligne: 10 de la commande - alter table "t_campagne_sms_execution" add constraint fk_repartition foreign key("cle_repartition") references "t_campagne_sms_repartition"("cle_repartition") rapport d'erreur - erreur sql : ora-02270: pas de correspondance de clé primaire ou unique pour cette liste de colonnes 02270. 00000 - "no matching unique or primary key column-list" *cause: references clause in create/alter table statement gives column-list there no matching unique or primary key constraint in referenced table. *action: find correct column names using all_cons_columns catalog view
i have tried via design this:
but still same error message.
if don't want add column in t_campagne_sms_execution create technical primary key on t_campagne_sms_repartition. t_campagne_sms_repartition_id simple number linked sequence (or identity column if have oracle 12, see doc here https://oracle-base.com/articles/12c/identity-columns-in-oracle-12cr1).
change primary key contraint unique constraint on t_campagne_sms_repartition keep behavior, , create new column in t_campagne_sms_execution link in newly created column.
the thing can't reference 1 part of composite pk because have no way sure it's unique.
hope helps
Comments
Post a Comment