If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > How do I Resolve Many to Many?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-18-09, 06:31
aboo aboo is offline
Registered User
 
Join Date: May 2006
Posts: 178
How do I Resolve Many to Many?

Hi,

Im abit confused on a scenario I have so here it goes.

Im trying to design a database where I create "Work Orders" for jobs that need to be done around the depot.

These Work orders contain various attributes like Worktype, Location,Date etc..

Sometimes it is required to have certain "Tools" and "Materials" to do these jobs. There is no cost i need to take into account as it is dealt internally.


My problem is that each work order can contain many tools or materials and that many tools or materials can be associated to many work orders.


I have used a tool called "Case Studio" to design my ERD but when created a many to many realtionship it auto created 2 new tables.

I have attached the ERD so you can see what i mean. Is there anyone who can help me see where i am going wrong?

Many Thanks

Aboo
Attached Thumbnails
How do I Resolve Many to Many?-erdtest2.jpg  

Last edited by aboo; 01-18-09 at 08:49.
Reply With Quote
  #2 (permalink)  
Old 01-18-09, 08:12
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
what do you see as wrong? the ERD looks fine to me

to implement a many-to-many relationship, an intermediate association or relationship table is required, which has columns that are FKs to the respective many-to-many tables, and a composite PK for the relationship table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-18-09, 08:48
aboo aboo is offline
Registered User
 
Join Date: May 2006
Posts: 178
Hey R937, Thanks for your reply, im just having trouble understanding.


Well if i create this database using the entities in the ERD. What would happen if i just stored the OrderID in the Materials Table with the QTY and the CustomerID?

Woudl this not achieve the same results in access?
Reply With Quote
  #4 (permalink)  
Old 01-18-09, 11:12
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
Quote:
Originally Posted by aboo
Hey R937, Thanks for your reply, im just having trouble understanding.


Well if i create this database using the entities in the ERD. What would happen if i just stored the OrderID in the Materials Table with the QTY and the CustomerID?

Woudl this not achieve the same results in access?
No because then the key of Materials would presumably have to be (MaterialCode, OrderId, CustomerId) and you would therefore have to populate a Qty for each combination of MaterialCode, OrderId and CustomerId. Is that what you intended? If so, then your current diagram is wrong because it only has ONE Qty per MaterialCode.

This is an example of what data modellers call a dependency: "x determines Qty". To be sure you model your database correctly you need to identify dependencies before you start.

The rules being applied by your CASE tool are the principles of Normalization. Roughly speaking, the relevant rule is that the determinant for every (non-trivial) dependency should be a super key (the "determinant" is what I referred to as "x" above). If you aren't familiar with that idea then it would be a good idea to study a decent book on database modelling to help you understand what your CASE tool is trying to do.
Reply With Quote
  #5 (permalink)  
Old 01-18-09, 17:34
aboo aboo is offline
Registered User
 
Join Date: May 2006
Posts: 178
Hi dportas,

Again thank you for your response.
I think your right. My ERD is wrong. I want to have multiple QTY for each material, ie could have 500 Screws related to this OrderID.
Then again, wouldnt it be many to many as i can place another order for some screws again? (MANY screws can be on MANY Orders?)

All i want is to create a database where i can see what "materials" and/or "Tools" a Order associated to and Which customer Ordered it.

Have i totally missed the target?
Reply With Quote
  #6 (permalink)  
Old 01-18-09, 18:32
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
i don't think CustomerID should be part of the PK of the WorkOrder table

the Qty columns need to move out of the Materials and Tools tables, and into the Entity6 and Entity9 tables
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 01-18-09, 18:52
aboo aboo is offline
Registered User
 
Join Date: May 2006
Posts: 178
r937,

If i dont have it as a Foreign key how will i know which customer has placed that order? how will a customer be linked to the order?

aboo.
Reply With Quote
  #8 (permalink)  
Old 01-18-09, 19:01
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
ah, but CustomerID should be a FK in WorkOrder -- just not part of the PK
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 01-19-09, 02:43
aboo aboo is offline
Registered User
 
Join Date: May 2006
Posts: 178
Thanks for your help r937,

Im gonna give it ago today, see how it goes. I will post later today see how it pans out.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On