Help... .. Deciding one to many or many to many.. Type..

  • Thread starter Thread starter Ahmed
  • Start date Start date
A

Ahmed

Hi,
I am learning in Access 2007.... Through John and Jeff Book......Have
two tables.... e.g. 1. AllItems 2. ItemsCategories
Both has Primary keys .... If Items would be in one of categories..
ItemsCategories Key Would GO in
AllItems as Fk... But.. in Future... if Some items belong to more than one
category then
it would rewuire a Juctional table (e.g. ItemsNCategories)...
Should I make Juctional Table (for unknown Future addition convinience) or
Just use one to many
Relationship... Will it hurt to make juctional Table and Procede.. ?

Second question is.. Should Catagories be added .. Through form Direstly
binding table or Should
Create Query of Table categories and Bind Query to Form..

Many thanks In Advance.. Though very basic question .. will appreciate..
help.

Thanks. Ahmed
 
Hello Ahmed,

It won't hurt a thing to create a junction table now. In fact it is
recommended that you do. If there is the remotest possibility that an item
will belong to more than one category, you have a one-to-many relationship
and need the junction table. Your tables should look like:

TblItem
ItemID
ItemName
<other item fields as needed>

TblCategory
CategoryID
Category

TblItemCategory
ItemCategoryID
ItemID
CategoryID

You can use a form/subform to enter/edit/delete data. Base the main form on
TblItem and base the subform on TblItemCategory. Set the Link Master and
Link Child properties to ItemID. Use a combobox to enter CategoryID in the
subform. Set the rowsource of the combobox to TblCategory. Set the Bound
Column property to 1, Column Count to 2 and Column Width to 0;2.

If you need one-to-one help, I can help you for a small fee. Contact me.

Steve
(e-mail address removed)
 
You should always design for future change as much as you can. If it's at
all possible that an Item could be in multiple Categories EVER, then you
should create it as a Many-to-Many relationship. Modifying the data model
after data has been entered is far more difficult than doing it in the
beginning.

Many-to-many (M:M) relationships are extremely common in real-life, far more
common than many beginning database developers realize. As a result, you
should ALWAYS ask yourself if a One-to-Many relationship (1:M) is in fact a
M:M. One useful technique is to write you relationship in actual words, in
both directions. For instance, consider your question.

ItemCategories ---< AllItems

You can write the relationship like this:

Each ItemCategory can be in One or More AllItems
Each AllItems can have One and Only One ItemCategory

If both of these sentences are true, then you have a true 1:M.
However, if the following sentences are true:

Each ItemCategory can be in One or More AllItems
Each AllItems can be in One or More ItemCategory

(Or if it could ever be possible in the future), you have a M:M

Hope that helps some.

Oh, for what it's worth, it doesn't sound like you need to pay anyone to
help you just yet. <smile>
 
Back
Top