Two foreign keys referencing the same primary key

后端 未结 4 2156
心在旅途
心在旅途 2020-12-08 09:55

Is this okay to have two foreign keys in one table referencing one primary key of other table?

EmployeeID is a primary key in the employee table and appearing as a f

4条回答
  •  臣服心动
    2020-12-08 10:51

    Option 1 is a perfect solution. You may define foreign key constraint as following

    1st foreign key constraint for Timesheet_For column

    ALTER TABLE TIMESHEETTABLE 
    ADD CONSTRAINT fk_TimesheetTable_EmployeeTable
    FOREIGN KEY (TIMESHEET_FOR)
    REFERENCES EMPLOYEETABLE(EMPLOYEE_ID)
    

    2nd foreign key constraint for Entered_By column

    ALTER TABLE TIMESHEETTABLE 
    ADD CONSTRAINT fk_TimesheetTable_EmployeeTable_1
    FOREIGN KEY (ENTERED_BY)
    REFERENCES EMPLOYEETABLE(EMPLOYEE_ID)
    

提交回复
热议问题