0

I want to save multiple media links for each product. For that I have a product table and all media files are stored in Aws S3. In my case I only want to get all media links related to a product. I don't have requirement to find which media is related to which product.

In this case is it better to save all media links in the same product table or I should create a mapping table where product ID is used as foreign key. Later approach looks better bcoz it is normalised but first approach looks better bcoz I can get all related media links by looking only one table

  • 1
    normalized table is better – Jens Mar 16 '17 at 11:03
  • 2
    To get an answer to your question, read [Is storing a delimited list in a database column really that bad?](http://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad), where you will see a lot of reasons why the answer to this question is **Absolutly yes!** – Zohar Peled Mar 16 '17 at 11:05
  • @Jens, Thanx for your reply. I am confuse because if I use normalized table, I have to look into two tables to find all media links for a product where if I save all media links comma separate in the same product table I do not have to look into mapping table – sudesh yadav Mar 16 '17 at 11:09
  • Weill you ever need to update these links? Count them? try to compare links of one product with links of another one? Do any database work with them except selecting? – Zohar Peled Mar 16 '17 at 11:12
  • @sudeshyadav but storing values as csv is very bad db desing and make more Problems by complex queries. Such as "How many links do you have?" or update on of the links and so on – Jens Mar 16 '17 at 11:12
  • @ZoharPeled, No I do not need to update, count or compare. I could delete some links for a product and add some – sudesh yadav Mar 16 '17 at 11:18
  • There will not be any update operation on links of multiple products in one go – sudesh yadav Mar 16 '17 at 11:20
  • So, what will you do to delete a link if your links are in a single, comma separated string? You will have to use string manipulations such as `replace` to remove it. That alone is a good enough reason to choose a normalized structure. – Zohar Peled Mar 16 '17 at 11:21
  • I agree but update links operation will be one in millions and this operation will happen for only one product at one time – sudesh yadav Mar 16 '17 at 11:25
  • Seems to me like you are looking for someone to tell you it's OK to store data in a non-normailized way. Sorry, but I can't recommend that. – Zohar Peled Mar 16 '17 at 11:47

0 Answers0