Search code examples
mysqldatabaseentity-relationshipdiagramvisual-paradigm

2 foreign keys referencing 1 primary key


So my intention here is to make the "Employee" contain 2 references to the same Primary Key in the "EmployeeContactInformation" table. The reason for this, is I want my employee to contain 2 different copies of the same table. E.g. 1 for work contact info, another for home contact info.

How would I implement this and what relationship would I use?
I'm assuming 1 to Many?

Current database screenshot

Current database screenshot


Solution

  • Lets change the design of your database:

    • Creat a table named as ContactInfoTypes. It will hold the definitions of each ContactInfoTypes you want (in your case: workContactInfo and homeContactInfo). It will have two columns (contactTypeId, contactTypeName)
    • Add an extra column to named as ContactInfoType (DATATYPE number) in your EmployeeContactInfo TABLE. The Column ContactInfoType will hold a Foreign-Key value of above TABLE ContactInfoTypes

    When you insert a contact in TABLE: EmployeeContactInfo, you would have to Insert two rows (one with the number value stored against workContactInfo and one with the homeContactInfo).