Ms-access – Linking Fields From 2 Different Tables (Microsoft Access)

ms accessprimary-key

I am trying to link 2 fields from 2 different tables on Access but I will give an example to try and make the issue clearer.

I have 1 table called "Employee Details" which contains the field 'Employee Names' and 'EmployeesID'

The 2nd table is called Schedules" which contains the field 'Employee Names' and'EmployeesID'

The Employees ID is set to a primary key for table 1 but I do not know how to link/create a relationship between the 2 tables so that in the 2nd table the primary key remains the same.

Overall I want to be able to link the 2 fields so that the ID number remains the same throughout the tables.

Please may I be advised of how to solve this issue.

Thank you.

Best Answer

In your scenario, you have two 'entities':

  • Employees. These are stored in table Employee Details.

  • Schedules. Stored in table Schedules. A schedule stores an Employee ID and other information.

What you want to do is make sure that every schedule contains a valid Employee ID. That, you want to make it impossible to create a schedule with an Employee ID doesn't exist, and also to delete an employee from the Employee Details table if that Employee ID is currently being used in a schedule.

These requirements are handled by what databases call a foreign key constraint. In Access, you can use a graphical tool ('Relationships') to 'link' the Employee ID column in the Schedules table to the Employee ID column in the Employee Details table so that the constraints I described above are always met.

You can read up on foreign key constraints and Access' Relationships manager tool to accomplish this.