Solved

How do you assign forign keys in Access 2007

Posted on 2009-05-11
2
181 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now