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 > Many to Many relationship keys

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-09-04, 17:34
LeninTorres LeninTorres is offline
Registered User
 
Join Date: Nov 2004
Posts: 4
Many to Many relationship keys

I have a typical Product - OrderDetail - Order. In OrderDetail the primary key is conformed by idProduct+idOrder. Now, I need to keep track of the individual product ordered, to express something like "the product X ordered in order Y has zero o more defects.
I hope my question is clear, i can post my current design if necessary.
Reply With Quote
  #2 (permalink)  
Old 11-09-04, 22:19
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
could you please repeat the question? your many-to-many table and compound primary key is correct

perhaps you just need to add a defectqty column to the table?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-10-04, 08:06
LeninTorres LeninTorres is offline
Registered User
 
Join Date: Nov 2004
Posts: 4
Question corrected (with db design attachment)

I canīt place a simple defect counter, because each defect has a description (is a entity by itself) and the purpose of the application is to determine some information about the defects, such as the more ocurrent, and so on.

In the attached file you can see an Credit, CreditDetail And CreditCause. A Credit is a disclaimer (made by the customer) of defect found in an ordered product. In CreditCause we have the allowed causes of defects. I need to link each of the items ordered with one or more of this causes.

In the current design, I can't express "product ordered in that especific order had the following causes of failure: X Y Z "

Thanks
Attached Images
File Type: jpg db.jpg (29.8 KB, 150 views)

Last edited by LeninTorres; 11-10-04 at 08:20. Reason: Explanation of db design
Reply With Quote
  #4 (permalink)  
Old 11-10-04, 08:21
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by LeninTorres
I need to link each of the items ordered with one or more of this causes.
then you need a many-to-many relationship between the OrderDetail table and the CreditDetail table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 11-10-04, 08:34
LeninTorres LeninTorres is offline
Registered User
 
Join Date: Nov 2004
Posts: 4
I think that, but I am not sure How this relationship can be expressed. I mean, normally, in a many to many relationship you have two primaryKeys thah are "added" in the junction table. But in this case, Is legal to put the two fields composing the primary key of OrderDetail table with the fields composing CreditDetail table int a BIG primary key in the new junction table?

Help me please, I never faced a problem like this before.
Reply With Quote
  #6 (permalink)  
Old 11-10-04, 08:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
yes, that is how you do it, migrate each of the primary keys, even if they are composite) as foreign keys into the relationship table

note you will not need 2 idPRoduct columns, just one
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 11-10-04, 08:50
LeninTorres LeninTorres is offline
Registered User
 
Join Date: Nov 2004
Posts: 4
First thing first: Thanks for prompt reply. I will now do the new design and i hope you can check it
Reply With Quote
  #8 (permalink)  
Old 11-12-04, 23:13
certus certus is offline
Registered User
 
Join Date: Dec 2003
Location: Canada
Posts: 710
Question: Are the causes of failure quantified or qualified? Would you need to have a boolean failure column in the variety, flower and grade tables? Seems like it would be more informative than simply saying the product failed.
__________________
visit: relationary

Last edited by certus; 11-12-04 at 23:23.
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