simple sql question on a good practise.

Discussion in 'MySQL' started by passingTime, Jul 13, 2012.

  1. #1
    In a relational database do you have to create a seperate table for repeating values that go above 3 digits?

    So for example, you have different containers and each container holds a different amount. One holds 10ml but another may hold 1000ml. Would you create a different table containing those values of 1 and 1000 or would you just let them repeat if the chance did occur.

    So e.g.

    BOTTLES ~~~~ VALUES
    bottle 1 ~~~~ 1ml
    bottle 2 ~~~~ 100ml
    bottle 3 ~~~~ 100ml
    bottle 4 ~~~~ 100ml
    bottle 5 ~~~~ 1000ml

    OR would you relate them?

    BOTTLES ~~~~ foreign KEY
    bottle 1 ~~~~ 1
    bottle 2 ~~~~ 100
    bottle 3 ~~~~ 100
    bottle 4 ~~~~ 100
    bottle 4 ~~~~ 1000


    I hope i made sense.
     
    Solved! View solution.
    passingTime, Jul 13, 2012 IP
  2. #2
    I think the answer would depend on the situation. If it's purely a volume based relation, and there's likely a ton of potential volumes possible, then it would be appropriate to reference a volume table. You would technically need 3 tables to accomplish this to prevent duplicates of the same bottle. The bottle table, the volume table, and a 3rd that contains the reference from the primary to the volume table. This would allow you to reference multiple possible volumes to the same bottle without actually duplicating the bottle itself. Realistically, if there's a low number of volumes, it's may just be overkill to make a completely separate table for them. If your interest is the most normalized method possible, go with the 3 table approach. If some degree of de-normalization is allowable I would keep it in one table for the sake of simplicity.
     
    jestep, Jul 13, 2012 IP
  3. passingTime

    passingTime Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Much love for your insight, you have helped me plenty with your answer.

    Thank you.
     
    Last edited: Jul 14, 2012
    passingTime, Jul 14, 2012 IP