Solved

How do you assign forign keys in Access 2007

Posted on 2009-05-11
2
187 Views
Last Modified: 2012-05-06
having trouble assigning forign keys
0
Comment
Question by:1030071002
2 Comments
 
LVL 12

Accepted Solution

by:
geowrian earned 25 total points
ID: 24361066
In a nutshell, you have a primary key from table x and the foreign key in table y. Make sure the types are compatible (i.e. an autonumber in table x with a long integer in table y). That's basically it. Depending on the indexing options you select on the foreign key, the type of relationship will change (i.e. indexing: yes with duplicates allowed will create a many-to-one relationship).

To enforce referential integrity (as is often what people are looking for with access databases from my experience):
1) Right-click off a table and choose "Relationships".
2) Add tables x and y to the view, if they are not already there.
3) Drag the primary key in table x to the foreign key in table y
4) Check enforce referential integrity and the cascading options you need.
0
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 25 total points
ID: 24363591
Access can handle most of the heavy lifting, if you setup your tables as geowrian describes. For example, most of the time in Access a foreign key relationship is handled through either (a) a combo or listbox or (b) a subform. If you use a combo/listbox, then you simply set the ControlSource of that control to the field in your table that would house the foreign key value, and you'd set the RowSource of the control to show the records from the foreign table.

If you use a Subform, you'd set the Master/Child links to reflect the relationship between those two tables, with your Master being the "one" side of the 1-to-Many relationship, and the Child (i.e. subform) being the "Many" side of that relationship.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question