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 > Need Relationship Advice (ha ha... corny!)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-28-06, 12:52
Sucoyant Sucoyant is offline
Registered User
 
Join Date: Jun 2003
Posts: 76
Need Relationship Advice (ha ha... corny!)

I need to create a database that houses food product information. A primary deliverable will be a report that looks similar to the ‘nutrition information’ found on product packaging:
http://www.radiantrecovery.com/georgegif.gif

This is what I have thus far (not complete… I don’t have all fields and whatnot):
http://www.netphetamine.com/upload/s...brelations.gif

I’m a bit confused as to how I should store the nutritional information. I’d appreciate any and all suggestions…

Thanks!
Reply With Quote
  #2 (permalink)  
Old 06-28-06, 12:59
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
you need a separate table for ingredients
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-28-06, 13:07
Sucoyant Sucoyant is offline
Registered User
 
Join Date: Jun 2003
Posts: 76
I thought about that... but is it really needed? How would you set up the relations then?
Reply With Quote
  #4 (permalink)  
Old 06-28-06, 13:14
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
yes it is really needed

where would you store ingredient information then? redundantly for each supplier?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 06-28-06, 15:48
Sucoyant Sucoyant is offline
Registered User
 
Join Date: Jun 2003
Posts: 76
Well then, how would I store the price of the ingredients? The price depends on the supplier....
Reply With Quote
  #6 (permalink)  
Old 06-28-06, 16:45
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
...another table for ingredient price.

You should do some research on the principles of database normalization. Otherwise, you are going to find yourself with a lot of bloated code trying to work around shortcuts made in your database design.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #7 (permalink)  
Old 06-28-06, 16:57
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
if the ingredient price is dependent on the supplier, then it goes exactly where you have it, in the Supplier_Ingredients table

all i'm saying is that the columns which define an ingredient (e.g. its name, recommended daily minimum, etc., which are not going to vary by supplier) should go into a separate Ingredients table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 06-29-06, 04:28
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,246
if you are goiong down the price route, you may also need to cater for product / ingredient equivalance. Ie subtitue product X with Product Y, the fun and games occurs if you also have to substitue product quantities (eg replace a 25Kg bag of X with 10 x 2.5Kg bags of Y.

if you can avoid the latter like thre plague, it becomes horredndously complex to model
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #9 (permalink)  
Old 06-29-06, 08:29
Sucoyant Sucoyant is offline
Registered User
 
Join Date: Jun 2003
Posts: 76
Quote:
Originally Posted by r937
all i'm saying is that the columns which define an ingredient (e.g. its name, recommended daily minimum, etc., which are not going to vary by supplier) should go into a separate Ingredients table
I realized that I didn't make myself clear and I may be causing some confusion. I'm sorry about this, it's been a long week.

In my first post, I said:
"looks similar to the ‘nutrition information’ found on product packaging"
What I meant to say is:
"looks similar to the ‘Supplement Facts’ found on product packaging"

I don't know how to relate the things like vitamins, calories, protien and whatnot to the product. The ingredients are simple, as they are static and don't require an amount. The other things I mentioned, though, require an amount.... and this is where I'm stuck.
Reply With Quote
  #10 (permalink)  
Old 06-29-06, 08:45
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
some ingredients have an amount, some have a percentage (of recommended daily amount), and some have both

Fat 3g 5%
Cholesterol 15 mg
Sodium 620mg 26%
Vitamin A 15%
__________________
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