Home > database >  Relating data from one table to another in mySQL
Relating data from one table to another in mySQL

Time:12-08

Here I have a EER diagram I am creating in the MySQL editor.

EER Diagram

I want Person to relate to employee. I want some Persons entries to be employees/Customers/etc.

How would I implement this? Would it be a shared key? Join the tables? Related data?

I tried making EmployeeID a foreign key to PersonID. The tables still don't "relate". (There's no way to tell what employee X's name/dob/ect is.)

CodePudding user response:

I encourage you to try again in the direction of making employeeID refer to personID, as a foreign key. You may not have implemented the whole idea.

The technique has a name: Shared Primary Key. If you search on this phrase, you will find articles describing what you have to do when adding a new employee. Without taking the correct steps when a new employee is added, you break the relationship between the two tables.

There is a tag with this name here in StackOverflow. enter image description here

  • Related