Skip to content
Advertisement

Multiple strings in one SQL field

I am trying to revamp an order system for an e-commerce web site. The header table for the orders is tbl_orders, that’s working fine but there is another table underneath that (so to speak) called tbl_orderitems

In this table tbl_orderitems I store an Id that refers to the items image but sometimes there is more than one image associated with an item so i’m now thinking of ways to store more than one filename in one field.

So let’s say the field is called Filename, this might be a varchar(400) for e.g. I would want to store more than one filename like

Images/cards/sides/complete/145.jpg, Images/cards/sides/complete/146.jpg, Images/cards/sides/complete/147.jpg

So, my first idea is to save it as comma delimited, but what I’m asking is – is there a better way to do this? As in, a faster way? I will be using ASP.NET C# to read this data out and will need to iterate through the strings. I have recently been using JSON, is it worth using this?

Advertisement

Answer

Create a separate table with two columns that associates order-item ids with filenames.

If it’s possible for order-items to share files, then I’d suggest you also create an “images” table that stores image-id and filename (and whatever other attributes you want to associate with an image), and replace the filename column in the first table I mentioned with the image-id.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement