Veli Izzet said:
Table1 is the main table
Table2 is the sub table
Table3 is the table thatr relates Table1&Table2
Yes, ok..then my advice is correct.
I really don't like using the term table3 relates table1 and table2. The
often used term is a junction table. (what on earth is that?).
When I explain relation stuff to people, I don't use the term junction
table, and I NEVER use the concept that table3 relates two tables. (it just
confusing the heck out of everyone).
So, my advice I mentioned to you still remains.
However, lets take up a quick example of what I mean here, and give some
meanings to those tables.
So, I going to use table1 - tblPeople (so, we can change/give each table a
meaning).
We want to make a database of our friends, and we want to track their
favorite colors. So, the first thing we need is a table of our friends
table1 - tblPeople our "main master" table of people
this table would have fields like:
id - Pk (primary key...likey a autonumber id),
FirstName
LastName
etc.
The next thing we need is a table to list out, or keep track of their
favorite colors. This table will be RELATED to table1
table3 - tblFavorateColors
Table1_ID - this realates to table1
Color - our favorite color
table2 - tblColors
Color (pk)
At this point, you might start to argue that table3 is related to table2,
but really, it is not. If you add, or delete records in table3
(tblFavorateColors), then we do not have to add, nor delete records to
table2 (tblColors). So, in effect, table2 is just a list of colors in a
table sitting there. There is NO NEED to build a relation from table3 to
table2.
So, we could build a form based on table1 (tablePeople), and the sub-form
would be the list of their favorite colors.
John smith
--->sub form
red
green
So, we can see that john smith has two favorite colors. At no point did we
join in, or use table2 here. However, often the PK would not be something
like a color, and thus a user cannot normally "remember" those values. Thus,
you OFTEN use a combo box that stores the id, but displays some text.
To be fair, you can (and should) enforce referential integrity from table3
(list of colors) to the lookup table of colors (tblcolors). Why? Well, you
might want to delete a un-used color, and if you got RI, then you cannot
delete a record in tblColors (table2) if any of them are being used in
table3.
So, to state that the table3 is used to relate the two tables is not the
best way of explain things. Table3 is related to table1. Each new record
you add to table3 is related to table1. Table3 is NOT related to table2. It
is the other way around!! So, table2 is related to table3!!
If you look at the relationships window, you will get:
table1----->table3--------->table2
Looking at the above, I don't see table3 relating the two tables, the arrows
are ONE direction.. We might have:
table1----->table3--------->table2------>table4
So, in the above each table only has ONE parent table. This whole concept
goes ONE way.....
You relate ONE table to another. That is ALL you can do, and it keeps the
whole thing very simple.
Each table only has ONE parent table.....
So, you can say you need a junction table..but I think it is MUCH more clear
to simply state that you need a table that lists peoples favorite colors.
And, if you want a list of colors, then make a table called "listofcolors".
So, you start at the top...and keep working you way down, one table at a
time....