我目前在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.
更多推荐
在表中存储/检索阵列的最佳方法
发布评论