0

I need to create a foregin to a composite primary key but it dosn't operate. I think the problem is when i reference the foregin key table

CREATE TABLE CLEPRIMAIRE
(
    aa INT,
    bb INT,
    
    CONSTRAINT PK_AA_BB PRIMARY KEY (aa,bb)
);

CREATE TABLE CLEPETRANGERE
(
    ee INT,
    ff INT,
    
    CONSTRAINT PK_EE PRIMARY KEY (ee),
    CONSTRAINT FK_FF FOREIGN KEY (ff) REFERENCES CLEPRIMAIRE(aa,bb)
);

I tried to code it put it dosn't work

Rapport d'erreur -
ORA-02256: le nombre de colonnes de référence doit correspondre au nombre de colonnes référencées
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.
Psykoxen
  • 1
  • 1
  • 3
    You need two seperate columns to store a two part composite key https://stackoverflow.com/questions/9780163/composite-key-as-foreign-key-sql – Portal Oct 26 '22 at 13:50

1 Answers1

0
CREATE TABLE CLEPETRANGERE
(
    ee INT,
    ff INT,
    gg INT,
    
    CONSTRAINT PK_EE PRIMARY KEY (ee),
    CONSTRAINT FK_FF FOREIGN KEY (ff, gg) REFERENCES CLEPRIMAIRE(aa,bb)
);

Is it what you need?