Creating a composite key

L

Lorna_Jane

Hopefully this is a really simple question, but in all my playing around with
access and looking through my textbook and reading through these forums I
have not been able to find out how to create a composite key. Could someone
please give me a step-by-step of how to do it?
 
S

Sylvain Lafontaine

For a primary key, select the two fields (when the table is in design mode)
before clicking on the Key symbol on the menu.

For an index, enter the second field below the first but don't give it any
index name (for the second field only).
 
G

Graham Mandeno

Hi Steve

This won't work. You will only succeed in changing the primary key from the
first field to the second one.

Lorna-Jane: Sylvain has the correct procedure. Note that you must first
display the Indexes window, either by View>Indexes, or by clicking the
Indexes button on the toolbar.
 
J

John W. Vinson

Hopefully this is a really simple question, but in all my playing around with
access and looking through my textbook and reading through these forums I
have not been able to find out how to create a composite key. Could someone
please give me a step-by-step of how to do it?

Open the table in design view.
Ctrl-click each field (up to ten) that you want included in the composite
primary key. Each field should darken to indicate that it has been selected.
Click the Key icon on the toolbar.

You will now have a composite key, allowing any one (or any subset) of the
fields to be duplicated but disallowing records with duplicates in all the
fields.

If you want to have the same set of fields as foreign keys in another table,
include them in the second table's design (with the same sizes and datatypes);
in the relationships window join *all* of the primary key fields to the
corresponding foreign key field. Set referential integrity on all of them (I
think that's needed but I'm not certain).

It's often easier to use a surrogate primary key such as an Autonumber, and
just create a unique index on your composite of fields.
 
S

stephanieguitard

Lorna_Jane said:
Hopefully this is a really simple question, but in all my playing around
with
access and looking through my textbook and reading through these forums I
have not been able to find out how to create a composite key. Could
someone
please give me a step-by-step of how to do it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top