D
David W. Fenton
Side-issue: Person-to-Company sounds like a many-to-one
relationship. I thought the purpose of join tables was to handle
many-to-many relationships.
Person-to-Company is very often a many-to-many because a person can
have a position at more than one company/organization. I could be
both president and CEO of ACME Corp., and also on the board of
InfiniCorp, and then a partner in PrivateVentures, LLC. What I've
just described is N:N for person/company, and 1:N for a person's
position(s) within each company.
Main issue: I like the concept of composite keys, but I read
somewhere on the internet from one published expert that composite
keys should be avoided because they create problems.
They do. They repeat a whole lot of data, which means you lose the
efficiency of Jet/ACE when retrieving the index pages, and then only
the needed data pages. If most of the data is in the foreign key,
Jet/ACE may not need to retrieve anything but the index, but the
number of index pages isn't going to be much larger for the same
number of rows, so I'd think that those composite keys would cause a
lot more data to be pulled across the Internet.
I don't use a composite key for any table whose PK is the foreign
key in another table. That is, if the table is not the parent in a
relationship with another table, a composite key is fine, particular
if it's a composite key of foreign keys, as in a many-to-many join
table.
My own experience is that even though Access
knows that a composite key is two fields that sometimes act as
one, Access apparently does not provide ready-made support for
this reality. For example, I like to use a list box as a
navigation tool to allow the user to pick a record, but this won't
work with composite keys because the list box is incapable of
passing the value of more than one field.
Well, not as a bound column, but you can still get the data in the
other columns. I think you use ItemData(i).Column -- I always have
to look it up, to be honest.
But for a bound listbox, it doesn't work well.
I don't bind many listboxes, but I certainly use lots of bound combo
boxes, and the problem with composite keys is identical there.
Another question: In your first example, does your junction table
actually store PersonID and CompanyID twice, once as PK and again
as FK?
No. I was describing the INDEXES not the fields. The table has only
the two fields, and there's a composite PK made up of the two
fields, and each field is individually a FK.