Using a 'joining' table

  • Thread starter Thread starter Mus' via AccessMonster.com
  • Start date Start date
M

Mus' via AccessMonster.com

Hi

Not exactly sure what I'm asking here but looking at some legacy Db's I've
noticed that some seem to use a 'joining' tables that consists of just two
Foreign Keys, set to Number. As far as I can tell these are used to relate to
child data sets with the same parent. Just wondering what the pro & cons are
of this as oppose to simply putting the FK's diectly into each table/.

Also, with a unary relationship (the classic Employee is also a Manager), how
would you set this relationship up?

Many Thanks
 
The junction table is the standard way to resolve a many-to-many
relationship into a pair of one-to-many relationship. Example and
explanation:
Relationships between Tables (School Grades example)
at:
http://allenbrowne.com/casu-06.html

To create a self-join, add a 2nd copy of the table to the relationships.
Access will alias it with a "_1" suffix. You can now join the foreign key of
this table to the primary key of the original copy of the table.
 
Dear Mus:

There are three types of relationships: one-to-one, one-to-many, and
many-to-many. This is how a many-to-many relationships is constructed.
This is common and proper (if they've done it right).

The "extra" table is a junction table showing which rows from each table are
related. I do not believe it can be implemented with just the two tables,
as you seem to think. If you invent a way to do that, please let us know!

Now, considering all managers are probably employees, I would set up a
relationship with the one side being EmployeeType: Regular, supervisor,
manager, executive. The other table of all employees wuld be the many side.
This one is usually pretty simple. But, if it is necessary to say someone
is both a regular employee and an executive, but not a supervisor or
manager, then it would need to be a many-to-many relationship. On the form
of employees, I'd create this by having a multi-select combo box of all the
EmployeeTypes, and have it highlight those that are chosen.

If you think you're going to put the 1 to 4 Employee types (listed above in
my example) all into the one employee table row, please consider how you
will do this and allow them to expand to 1000 EmployeeTypes, without
changing the Employee table. Or 1,000,000 Employee Types. The method we
use now, the junction table, allows for all this, without any change to its
initial design. Also, this method queries well. Junctions tables were
taken into consideration when query languages were developed.

It may be useful to think of the whole setup as a giant 2-dimensional
matrix. The rows and columns are labelled as employees and employee types.
The intersections are marked whether the employee is of that type or not,
that being determined by whether the junction table has a row for that
combination of employee and employee type or not. In addition, you can
store information about that employee being of that type, such as the year
he became a manager, or who promoted him. Someone could even be a manager,
get fired or quit, get re-hired, and be a manager again. Key the table on
the employee key, the employee type key, and the date hired or promoted.
The same person can then be hired or promoted to be a manager, then not be a
manager (maybe save the date of that in the junction table, too) then be a
manager again, over and over. So, having a place (the junction table) to
store information specifically about that employee at that type is valuable.

There's a lot more to making it work than just this, but that's a start.
The rest is generally VBA code behind the form, to make the list box appear
with the appropriate lines highlighted (Current event) and to save any
changes made (Before Update event).

Please let me know if this helped, and if there is more with which I can
assist you.

Tom Ellison
 
Thanks Guys for the replies and information, I think I'm getting it now.
Initially I just acknowledged the parent /child relationships not the
childrens relationship to each other.

I notice that in the junction tables both FK's are set as PKs. Just figured
how to do this. Is this a must on all junction tables?

BTW, apologies for a little confusion, the second question was not related to
first but just thought I'd ask as we were on the topic of relationships.

Cheers

"Just learning something new everyday" ;o)
 
The junction table can have any primary key that is appropriate - AutoNumber
of whatever you like.

If you want to guarantee that the combination of the two foreign keys cannot
be duplicated, then it makes sense to use the combination of the 2 keys be
the primary key of the junction table. But if you want to allow these to be
duplicated, you must not use the combination as the p.k.
 
OK got it. Thanks Allen.

Allen said:
The junction table can have any primary key that is appropriate - AutoNumber
of whatever you like.

If you want to guarantee that the combination of the two foreign keys cannot
be duplicated, then it makes sense to use the combination of the 2 keys be
the primary key of the junction table. But if you want to allow these to be
duplicated, you must not use the combination as the p.k.
 
Back
Top