Getting error msg:' number of referencing columns must match referenced columns'

Hi,

I’m a uni student.

For one of our exercises in class we have to create tables based on erd.

The erd had 4 tables. 2 tables were strong entities - employee and project
3rd table was allocation and was a weak entity representing the many to many relationship between employee and project
4th table was timelog and was a weak entity and depended on the allocation table

The error message I get is:
‘CONSTRAINT CC_Timelog_EmpID_FK FOREIGN KEY(EmpID) REFERENCES ALLOCATION,
*
Error at line 7:
ORA-02256: number of referencing columns must match referenced columns’

I know that I have made an error with creating the timelog table, but don’t know how to fix it.

Can anyone please help me out and let me know what I am doing wrong.

Thanks.

Below is the sql code:

–CREATING TABLES BEGINS–

Prompt Creating table EMPLOYEE;
CREATE TABLE EMPLOYEE(
EmpID Number,
EmpName Varchar2(50),
Gender Varchar(3),
CONSTRAINT CC_EmpID PRIMARY KEY(EmpID)
);

Prompt Creating table PROJECT;
CREATE TABLE PROJECT(
ProjID Varchar2(50),
Budget Number,
Description Varchar2(50),
CONSTRAINT CC_ProjID PRIMARY KEY(ProjID)
);

Prompt Creating table ALLOCATION;
CREATE TABLE ALLOCATION(
EmpID Number,
ProjID Varchar2(50),
HourlyRate Number,
CONSTRAINT CC_AllocaID PRIMARY KEY(EmpID, ProjID),
CONSTRAINT CC_ALLOCATE_EmpID_FK FOREIGN KEY(EmpID) REFERENCES EMPLOYEE,
CONSTRAINT CC_ALLOCATE_ProjID_FK FOREIGN KEY(ProjID) REFERENCES PROJECT
);

Prompt Creating table TIMELOG;
CREATE TABLE TIMELOG(
EmpID Number,
ProjID Varchar2(50),
WeekNo Number,
HrsWorked Number,
CONSTRAINT CC_TimelogID PRIMARY KEY(EmpID, ProjID),
CONSTRAINT CC_Timelog_EmpID_FK FOREIGN KEY(EmpID) REFERENCES ALLOCATION,
CONSTRAINT CC_Timelog_ProjID_FK FOREIGN KEY(ProjID) REFERENCES ALLOCATION
);
–CREATING TABLES ENDS–

ALLOCATION has a 2-column primary key

therefore, if TIMELOG is to reference ALLOCATION, the foreign key must also have 2 columns

thus, you got the error message “number of referencing columns must match referenced columns”

Thanks,

I fixed it now.

shippuuden