在表中存储/检索阵列的最佳方法 [英] Optimal Way to Store/Retrieve Array in Table

查看:59
本文介绍了在表中存储/检索阵列的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在MySQL中有一个表,该表可以正常存储值,但是我想向该表中添加一个字段,以存储值的数组,例如城市.我应该简单地将该数组存储为CSV吗?每行都需要它自己的数组,因此我对创建一个新表并为上一张表中插入的每一行插入2-5行感到不安.

I currently have a table in MySQL that stores values normally, but I want to add a field to that table that stores an array of values, such as cities. Should I simply store that array as a CSV? Each row will need it's own array, so I feel uneasy about making a new table and inserting 2-5 rows for each row inserted in the previous table.

我觉得这种情况应该有个名字,我只是想不起来:)

I feel like this situation should have a name, I just can't think of it :)

编辑

元素数-2-5(从动态城市列表中进行选择,数组引用该列表,即表格)

number of elements - 2-5 (a selection from a dynamic list of cities, the array references the list, which is a table)

此字段无需搜索,只需与其他数据一起检索即可.

This field would not need to be searchable, simply retrieved alongside other data.

推荐答案

正确"的方法是拥有另一个保存每个值的表,但是由于您不希望使用该方法,所以定界列表应该起作用.只要确保您选择了不会出现在数据中的定界符即可.您还可以将数据存储为XML,这取决于您计划如何与数据交互,这可能是更好的方法.

The "right" way would be to have another table that holds each value but since you don't want to go that route a delimited list should work. Just make sure that you pick a delimiter that won't show up in the data. You can also store the data as XML depending on how you plan on interacting with the data this may be a better route.

这篇关于在表中存储/检索阵列的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆