Newbie question - what is a Foreign Key and how do you define it?

  • Thread starter Thread starter Mike Matheny
  • Start date Start date
M

Mike Matheny

I saw a posted question that is similar to a problem I am having, and the
reply was to use a foreign key in one of the tables that feeds the form.
 
a foreign key is usually the primary key field from a
related table. you use it to link the records in one table
to records in another table.
a classic example is two tables, tblCustomers and
tblOrders:

tblCustomers
CustID (primary key)
CustName
CustStreet
CustCity
etc...

tblOrders
OrdID (primary key)
Ord_CustID (foreign key)
OrdDate
etc....

this is a one-to-many relationship. one Customer can have
many Orders, and each Order belongs to only one Customer.
using the primary key field from tblCustomers as a foreign
key in tblOrders means that each order is matched to a
particular customer - but you only have to enter the
customer's data one time in one place.

suggest you read up on data normalization and table
relationships. you should design your tables/relationships
correctly before building the rest of your db, rather than
trying to "fix" them as you go along.

hth
 
Thanx - I took over a project my boss started, and it is not real complex
yet, so I will read up on data normalization and probably just start over
from scratch, so I can figure out what is going on!
 
Mike,

When linking 2 tables together, you will link 2 fields (one from each
table). The main table will link the field by using it's primary key
(normally), and the sub table field would be the foreign key. Do a search on
Foreign in the MSAccess help files and it will explain this further.

HTH,

Neil.
 
Back
Top