To re-phrase the question, do the foreign keys have the same data
content as the primary keys? What content can I expect to see in these
foreign keys when I view the junction table in Datasheet view?
Maybe I have to somehow copy the data or the these fields somehow from
the parent tables to the child table?
Yes, you got it well right...
Also, while many people use the term "junction table", from a ease of
thinking, and relation point of view, it is must better to just think in
terms of a table.
For example, I have a order table, let call it tblOrders.
I also have a table called tblParts.
For each tblOrder, I need to "list" the parts needed. So, lets make a table
called tblOrdersListOfParts.
Calling something a "junction" table kind of confuses the issue. And, in
fact, tblPartgs is really a lookup table in the sense that you can delete,
or add many orders, and you can add, or delete many tblOrdersListOfParts
records, but in no case do you actually delete anything, or add anything in
the parts table.
The only reason why we got a pats table is because we cant remember the
parts by memory. However, the only real enforced relationship here is that a
between tblOrders, and tblOrdersListOfParts. we are free to add, or delete
tblOrdrs records, but they never effect tblParts. In fact, we are free to
delete records in tblOrderListOfParts, and again we never delete, or do
anything to tblParts.
So, I got a table called "orders"
For each order, I might have "many" parts, so, we need a table called
tblOrdersListOfPartrs.
And, our description of parts is also needed, so we got a table called
parts.
Notice I never started talking about confusing junction tables here..
What I dont understand is if the primary keys are set to autonumber in
the parent tables, do I have to create new fields in the junction table
with the same name as the primary keys in the other tables and format
them to number and then add all the autonumber data in manually?
Yes. Note that the names of the fields do NOT need to be the same as the
parent table. In fact, since each table "defaults" to "id" for the primary
key autonubmer, then why not adopt that as a standard for all tables. That
means every table you have will always have a autonumber field called "id".
You never have to write this down, or "know" that is the case, since all
pk's will be this.
Now, for the child tables, you may, or may not need a primary key, but, if
you do, then again, you use "id", and autonumber. However, for those fields
that you were just asking about, they MUST be defined as the SAME data type
(eg: long number = autonumber), but of course can't be a autonumber field.
These are regular "long number" fields. So:
and then add all the autonumber data in manually?
Yes, you do. However, if you build a form, and a sub-form, them ms-access
will put in the values in the fields for you (you have to set the link
"master" and link "child" fields so the form can know to do this for you.
So, we would build a "main" form on our tables called "tblOrders"
We would build a sub-form for the "many" side. In this case tblListOfOrdres.
That sub-form would have three fields
id tblOrders_ID tblParts_id
The "id" is not of much use, but might come in handy in the future.
tblOrders_ID is the field used to relate back to the tblOrders. This field
is often called a foreign key.
tblParts_id is the field used to hold the parts id.
So, we could build a sub-form, and really we only need to display the
tblParts_ID field. A continues sub-form would make this look quite nice.
However, since we can't remember the parts id, then you simply could/would
use the wizard to build a combo box for the tblParts. The combo box would be
based on the tblParts, and would store the "id" to the field tblParts_id.
Note how elimination of talking about junction tables, and weird stuff makes
this whole concept a lot easer. Note also how for the tblparts_id, that the
USER IS going to set this value, not ms-access. We use a combo box here, so
the user dn't have to reember the actaull "id" used.
However, for the tblOrdres_ID, there is no need for the user to type in a
id, and our designs + forms should handle this for the user.
Note also how we name our fields that hold primary keys from other tables. I
use tablename + primary key name, and you get
tblOrders_ID
This means my poor little brain never has to make up a pk, or fk name, as I
adopted some naming scheme.