在表中存储/检索阵列的最佳方法

编程入门 行业动态 更新时间:2024-10-25 18:30:09
本文介绍了在表中存储/检索阵列的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前在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.

更多推荐

在表中存储/检索阵列的最佳方法

本文发布于:2023-10-23 06:09:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1520024.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:阵列   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!