Vincent,
Problem 1, that the SQL to delete a record is simpler with one key, is
correct, but both of the examples shown there work properly, so if you
don't delete records often, it may not matter to you.
...."so if you don't delete records often, it may not matter to you"? I'm
not sure what that statement is suppose to mean. Do you really want to create
solutions where deleting records is a bit more difficult than it needs to be?
What about the example of allowing a student to take a class multiple times,
or any other situation, where you might need multiple entries in the junction
table from tbl1 and tbl2? As the author pointed out, this would require one
(or more) additional fields be used as the combined PK.
Problem 2, that the key might not be unique, might not apply to you.
You'll probably want to define a "No Duplicates" index on your junction
table...
Well, since the title of the article is "Why to avoid composite Primary
Keys", you would have already had a "No Duplicates" multi-field index on the
foreign key fields that made up the combined PK for this table. I agree that
you may want to define a "No Duplicates" multi-field index on these two
foreign key fields if they are not used as a primary key, but by doing so,
you re-introduce the problem discussed in paragraph 1 (ie. allowing a student
to repeat a class multiple times). I can't really think of too many
situations where the bound column of a combo box is not unique in the
databases that I create.
Problem 3 also seems based on a premise that the combined key might not
be unique. If I understand this correctly, see my suggestion concerning
Problem 2.
I don't think you understood it correctly. The author was saying that if you
need a new table that is related one-to-many (1:M) to your junction table
(tblStudentClasses in this example), then you will need to include three
pieces of information in your new table (tblStudentClassTests) : StudentID,
ClassID and TestID. This would require two relationship joins defined to
enforce referential integrity:
tblStudentClasses.StudentID ----> tblStudentClassTests.StudentID and
tblStudentClasses.ClassID ----> tblStudentClassTests.ClassID
Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
:
The article makes some valid points, but consider them in light of your
own situation.
Problem 1, that the SQL to delete a record is simpler with one key, is
correct, but both of the examples shown there work properly, so if you
don't delete records often, it may not matter to you.
Problem 2, that the key might not be unique, might not apply to you.
You'll probably want to define a "No Duplicates" index on your junction
table, and your Combo Box would thus select unique values. You'll need
to be sure that the values really ARE unique, perhaps by trying to add
duplicate values and being sure that you get an error message. (Or
maybe I don't fully understand the writer's objection -- take what I say
with a grain of salt!)
Problem 3 also seems based on a premise that the combined key might not
be unique. If I understand this correctly, see my suggestion concerning
Problem 2.
In your case, if your junctional table does *not* need to have unique
keys, then you'll need some way to distinguish those that share a set of
keys, and by the time you add enough extra keys to make the records
unique, you might save a lot of trouble just by adding an Autonumber key
to the table and using that as your primary key.
-- Vincent Johns <
[email protected]>
Please feel free to quote anything I say here.
__________________________________________
Tom Wickerath wrote:
Hi Ahmed,
Here is an article that you might find helpful:
Why to avoid composite Primary Keys
http://www.utteraccess.com/forums/s...=247916&page=0&view=collapsed&sb=5&o=&fpart=1
Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
:
hi,
Thanks in advance..
I am having trouble with composit key..
is it wise to use composit key .. ?
If I want to use composit key of one table as foreign key in second table
.... I have to add (or create those fields
in second table.. ) those fields in second table .. is this
the correct way ?
e.g tbl1 with pktblfld , tbl2 with pktbl2fld , tbl3 with
pktbl1fld+pktbl2fld as Pk , and tbl4 having pktbl4fld,
fldprog,fldrostr and tbl3's PK which is pktbl1fld+pktbl2fld
am I in right direction pls explain am nu to access
Thank you very much