Multiple Primary Keys in a table?? (1 Viewer)

GaryVr

New member
Local time
Today, 04:30
Joined
Sep 12, 2017
Messages
5
Hi Folks,
New to MS Access so please forgive me if this turns out to be trivial ...

I am trying to build a database to keep track of my golf scores / handicap. I have found an excellent model from the databasedev uk web site which has a template model for golf scoring.

The relationship they describe is in the attached zip file.

My simple question, is given that MS Access only allows there to be one Primary Key per table, how do I define for example the tblPlayerRounds fields of lngPlayerID and lngRoundID?

Access will only let me make one of PlayerID or RoundID be the Primary Key. Do I pick one or not even use a Primary Key for that table?

Many thanks in advance for your help,
Gary
 

Attachments

  • Golf Structure.zip
    81.8 KB · Views: 117

GaryVr

New member
Local time
Today, 04:30
Joined
Sep 12, 2017
Messages
5
Thanks for the tip but ...

How do I define a compound primary key in Access (2016)?

In my example, I currently have lngPlayerID as the primary key. I can't find any mechanism in Access 2016 to make lngPlayerID and lngRoundID a compound primary key ...

In the Table Design View I only seem to be able to select one field at a time. In the Datasheet View I can select two fields but can't find an option to define them as a primary key ...

Many thanks in advance!
Gary
 

GaryVr

New member
Local time
Today, 04:30
Joined
Sep 12, 2017
Messages
5
JDraw ... I am an idiot ... please ignore my most recent post as I figured out how to set a compound primary key using the Design View ... sorry to waste your time ...

Cheers,
Gary
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 04:30
Joined
Apr 27, 2015
Messages
6,321
JDraw, thanks for your post and link(s). I can't believe 1): I have never heard of this and 2): I didn't think to find this answer in the past.

This will solve one of the MAJOR issue I have been having with my project.

Great tip, thanks again...
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 03:30
Joined
Feb 28, 2001
Messages
27,140
True, you can have only one primary key. It can be compounded. There are reasons to do so. TECHNICALLY, you can have more than one unique key in a table. Only one of those keys can be the primary.

HOWEVER, having multiple unique keys that are NOT compounded can cause issues. I have not opened the zip file. But here is the question you must ask yourself.

When you make a record with PlayerID and RoundID as the compound PK, does that uniquely define/specify the rest of the data in your proposed record? This is the BASIC question that you use to identify the primary key. IF the answer is NO, then you have selected the wrong key or combination thereof. If you answer YES (correctly) then BINGO, you've found the PK.

Since you claim you are a novice, I thought it might help you to know HOW to make that kind of selection.
 

GaryVr

New member
Local time
Today, 04:30
Joined
Sep 12, 2017
Messages
5
Doc Man ....

I think the answer is YES so I think I'm ok ... If you have a chance, please open the zip file and look at the simple graphic that shows the database structure to confirm.

Cheers,
Gary
 

Users who are viewing this thread

Top Bottom