开发者

Multiple strings in one SQL field

开发者 https://www.devze.com 2023-02-10 03:29 出处:网络
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 tb

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_orde开发者_运维技巧ritems 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?


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.


You can create two tables instead of one.

like following:

create table tbl_orderitemsgroup (
id int identity(1,1) not null )

create table tbl_orderitem (
id int identity(1,1) not null,
group_id int not null
)

with foreign key tbl_orderitem.group_id to tbl_orderitemgroup.id

0

精彩评论

暂无评论...
验证码 换一张
取 消