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 > Database Server Software > MySQL > Many to Many relationship: Is this correct?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-25-08, 14:55
GameOne GameOne is offline
Registered User
 
Join Date: Jun 2008
Posts: 2
Many to Many relationship: Is this correct?

Hi

I am new to this forum and also to SQL, DB design. I am stuck with a situation where I cannot define relationship between two tables. It goes something like this. Pls correct me whereever possible.

The first table 'Products' can have many 'Feature' and a 'Feature' can belong to many products (many to many). 'Feature' can be name-value pair or name-collection. I am storing the collection in the same column as value is stored and collection values are comma-separated values.

Now if a feature is assigned to a Product, one should be able to configure his own value for a product. For example, P1 and P2 are products and F1 is a collection type feature (V1, V2, V3). If i assign F1 to P1 and P2, then I should be able to configure its own value. V1 for P1 and V2 for P2.

How do I implement this kind of relationship?
Just as a work around i have created a new table P_F in which I have (Pid, Fid, Value), where 'Value' is each product's own feature value.

Pls help me.
Reply With Quote
  #2 (permalink)  
Old 06-25-08, 17:34
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
your "workaround" is the right solution

any time you find yourself storing a comma-delimited list of values in a single column, you are almost certainly making a very bad design decision
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-25-08, 17:38
GameOne GameOne is offline
Registered User
 
Join Date: Jun 2008
Posts: 2
hmmm, with that said... how can I replace the CSV solution with a better one? Any pointers?
Reply With Quote
  #4 (permalink)  
Old 06-25-08, 18:59
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
yes, what you want to do is create a table with the following columns:

- Pid
- Fid
- Value

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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