0

I been doing some research on normalization for mysql db. I realized that it's much more easier to have multiples tables rather than one table. I'm guessing it's much more easier to have a column for different values than combining it in one column. My question is what if I am designing a page that has a fixed info and I will always need to pull those info together. For example I have a column called T-Shirt Colors under the table CLOTHES. I would then store the value "Red - Blue - Green - Yellow - Orange - Pink - Dark Red " etc. and let's say that column value will have a very long string since it will contain over 1,000 colors. I know for SURE that these are the only colors my store will sell so I don't have to worry about adding or deleting the colors... Would it be more efficient on the overhead and server speed to do it this way and then explode the colors into a list...

I've been recommended to create a linked table for the colors... However:

Database Design A: (linked table design)

Table products - ProductID : - Name: - Shirt:

Table colors - ColorID: - Name:

Table product_colors - ProductID: - ColorID:

the numbers of tables and rows I would get based on 1,000 colors for a t-shirt would be:

Number of Tables : 3

Number of Columns : 6

Number of Rows : 2,002 -----> 2 ( from table products), 1,000 (from table colors), and 1,000 (from table product colors)

if I was to setup a table with three columns and just store all the colors together in a long string for the column colors (and explode it into a list when needed).... the amount of rows and columns I would get is:

Database Design B: (storing 1,000 colors in one long string and then exploding it into a list )

Table shirt_colors

Product ID:

Name:

Colors:

Number Of Tables : 1

Number Of Columns : 3

Number Of Rows : 3

Can anyone explain to me how Database Design Option A is more optimal (overhead and performance wise) than setting the colors into one long string value and then exploding it (besides the fact that it's easier to read and maintain)?

Database Design Option A : would result in 3 tables, 6 columns, and 2020 rows being created.

Database Design Option B : would result in 1 tables, 3 columns, and 3 rows being created.

I'm having a hard time understanding how Database Design Option A would be the more optimal choice from an overhead and performance perspective. I do realize that a column with a value of over 1,000 words can be very long, but I'm thinking it has no problem pulling up long strings since mysql is a very popular among article and forum sites.

Also if it is more efficient to explode the values (even though it's harder to maintain) on the overhead and server speed, approximately how many more times is it it more efficient.. 1X faster, 2X faster, 3X faster, etc. or maybe too little to be even notice? Thanks in advance

(keep in mind that these 1,000 colors are always going to be used together... Since they will always be pulled and used together to give the customer the color options to select from...)

Sam Bo
  • 23
  • 3
  • Go read about how to solve a many to many relationship. You are facing a classical many to many relationship problem here. Once you have specific questions about resolving your problem I will be more than happy to help. – Namphibian Jul 14 '13 at 08:35
  • I gotten a response recommending I created a linked table...But even then I still don't see how it is more optimal than storing the colors in one column, for this particular situation. I will re-edit my question with the linked table, to make my question more specific to the best of my ability. – Sam Bo Jul 14 '13 at 13:01
  • Firstly you need to make a decision based on facts not a hunch. So create both designs and test them. Storing everything in 1 column is going to burn you at some point but I am not going to deny you the privilege of struggle. Understand this 2020 rows are nothing it is so minuscule for the MySQL engine that it probably wont even need to use indexing. If you had over 1 billion rows then I would suggest a alternative design. Go experiment with both and find out what the up s and downs are. – Namphibian Jul 15 '13 at 05:50
  • 1
    I been doing a lot of reading with your advice in mind and i agree it's best not to put everything in 1 column. Much harder to sort or data if I ever need to. Thanks for the advice :) – Sam Bo Jul 16 '13 at 19:46

0 Answers0