D
dymondjack
Sorry everyone... I know this horse has been being beating for a long long
time, but despite all of my research, I'm still having trouble with a
decision on primary keys with many-to-many relationships.
I'm making my first attempt at a M:M relationship: Companies and Contacts
(one company, many contacts; one contact, many companies (rare in my case,
but it does happen)).
So I've got this junction table (in process of being) setup. Not too big of
a deal, I think I've got a decent handle on it (thanks MVPs), and I want to
make sure I'm not getting ready to kick myself later on. There's two
different ways I've seen these junction tables set up, with one field as a
PK, and with 2 fields.
1 Field example:
jtblCompCont
(0) fldCompContID <-- PK
(1) fldCompID <-- Child
(2) fldContID <-- Child
2 Field example:
jtblCompCont
(0) fldCompID <-- PK & Child
(1) fldContID <--PK & Child
Logic tells me to go with a 2 field PK, I think it makes more sense. (if I
want to assign a Title to the contact within that company, the 2 field
primary key makes sure that there will only be one contact ID for that
company, whereas the the 1 field key would allow me to duplicate that
information (bad bad bad, right?)).
The thing that worries me is that as I get deeper and deeper into the design
of this db, if I go with composite keys, at some point I'm going to wind up
with tables that require many more key fields that I want (or am allowed, if
I understand correctly access has a limit of 10 fields per key?). I don't
necessarily expect this problem with Companies and Contacts, but when I get
into Machines, Operations, Tools, Fixtures, Parts, etc, etc, I can see where
composite PKs could get pretty ugly...
But, if I go with a single field for a key, technically this would allow
duplicate records, but relating these tables down the line will be no issue
at all (one parent field, one child field... nice and simple).
I suspect the answer is to use a single field as a PK and be very careful of
data entry (leave it up to me to make sure there's no duplicates rather than
access).
Can anyone shed some light on this based on my scenario? I've never worked
with composite keys before, so I don't really know what I would be getting
myself into there.
Sorry for the long post but I've been pulling my hair out for the last two
days trying to get this figured out.
--
Jack Leach
www.tristatemachine.com
- "A designer knows he has reached perfection not when there is nothing left
to add, but when there is nothing left to take away." - Antoine De Saint
Exupery
time, but despite all of my research, I'm still having trouble with a
decision on primary keys with many-to-many relationships.
I'm making my first attempt at a M:M relationship: Companies and Contacts
(one company, many contacts; one contact, many companies (rare in my case,
but it does happen)).
So I've got this junction table (in process of being) setup. Not too big of
a deal, I think I've got a decent handle on it (thanks MVPs), and I want to
make sure I'm not getting ready to kick myself later on. There's two
different ways I've seen these junction tables set up, with one field as a
PK, and with 2 fields.
1 Field example:
jtblCompCont
(0) fldCompContID <-- PK
(1) fldCompID <-- Child
(2) fldContID <-- Child
2 Field example:
jtblCompCont
(0) fldCompID <-- PK & Child
(1) fldContID <--PK & Child
Logic tells me to go with a 2 field PK, I think it makes more sense. (if I
want to assign a Title to the contact within that company, the 2 field
primary key makes sure that there will only be one contact ID for that
company, whereas the the 1 field key would allow me to duplicate that
information (bad bad bad, right?)).
The thing that worries me is that as I get deeper and deeper into the design
of this db, if I go with composite keys, at some point I'm going to wind up
with tables that require many more key fields that I want (or am allowed, if
I understand correctly access has a limit of 10 fields per key?). I don't
necessarily expect this problem with Companies and Contacts, but when I get
into Machines, Operations, Tools, Fixtures, Parts, etc, etc, I can see where
composite PKs could get pretty ugly...
But, if I go with a single field for a key, technically this would allow
duplicate records, but relating these tables down the line will be no issue
at all (one parent field, one child field... nice and simple).
I suspect the answer is to use a single field as a PK and be very careful of
data entry (leave it up to me to make sure there's no duplicates rather than
access).
Can anyone shed some light on this based on my scenario? I've never worked
with composite keys before, so I don't really know what I would be getting
myself into there.
Sorry for the long post but I've been pulling my hair out for the last two
days trying to get this figured out.
--
Jack Leach
www.tristatemachine.com
- "A designer knows he has reached perfection not when there is nothing left
to add, but when there is nothing left to take away." - Antoine De Saint
Exupery