primary and foreign keys

merlin777

Well-known Member
Joined
Aug 29, 2009
Messages
1,397
Office Version
  1. 2007
I'm an access (2007) novice and I'm trying to grapple with table relationships.

I understand the concept of dividing data into different tables to avoid repetition but I just can't quite get a grip on primary and foreign keys. I think the bit I'm missing is how to choose the foreign key.

I think the primary key is fairly straightforward - it's any unique field such as a customer ID. I'm not quite sure why you just don't use the record number which is always unique - that might give you an idea why I'm not understanding.

And I'm not sure how you choose what to relate the primary key to in another table. Does your choice of foreign key need to have the same name as the primary key?

Help.... brain hurts.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I'll try to give you an example. I'm working towards an appointments database for medical appointments.

I want to end up with an appointment which includes:
patient name
therapist name
therapist job title
appointment time

I am thinking I need these tables:
Therapists table
therapist name
therapist job title

Patients table
patients name
NHS number
phone number

Therapist job titles table
senior therapist
therapist
junior therapist

appointments table

Patient's name
Therapist's name
Therapist's job title
appointment time
 
Upvote 0
A simple rule to follow (if you can) is that a foreign key in one table is the primary key in the other table - i.e., if OrderID is the Primary key of the Order table, then OrderID might work as a foreign key in the OrderDetails table.
 
Upvote 0

Forum statistics

Threads
1,221,788
Messages
6,161,963
Members
451,734
Latest member
Adapt375

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top