在数据库字段中存储数字数组 [英] Store array of numbers in database field

查看:717
本文介绍了在数据库字段中存储数字数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:SQL Server 2008,C#

Context: SQL Server 2008, C#

我有一个整数数组(0-10个元素)。数据不经常更改,但经常检索。

I have an array of integers (0-10 elements). Data doesn't change often, but is retrieved often.

我可以创建一个单独的表来存储数字,但由于某种原因,它感觉不是最优的。

I could create a separate table to store the numbers, but for some reason it feels like that wouldn't be optimal.

问题#1:我应该将数组存储在单独的表中吗?请给出理由的单向或其他。

Question #1: Should I store my array in a separate table? Please give reasons for one way or the other.

问题2:(无论Q#1的答案是什么),什么是最好的在数据库字段? XML? JSON? CSV?

Question #2: (regardless of what the answer to Q#1 is), what's the "best" way to store int[] in database field? XML? JSON? CSV?

EDIT:
某些背景:存储的数字只是一些不参与任何关系的系数,

Some background: numbers being stored are just some coefficients that don't participate in any relationship, and are always used as an array (i.e. never a value is being retrieved or used in isolation).

推荐答案

最好的方式将数据存储在数据库中是最有利于将对其执行的操作的方式和使得维护最容易的方式。正是这个后来的要求应该导致你到一个规范化的解决方案,意味着存储在一个表中的关系的整数。除了更容易更新外,下一位开发者更容易了解信息的存储方式和方式。

The "best" way to store data in a database is the way that is most conducive to the operations that will be performed on it and the one which makes maintenance easiest. It is this later requirement which should lead you to a normalized solution which means storing the integers in a table with a relationship. Beyond being easier to update, it is easier for the next developer that comes after you to understand what and how the information is stored.

这篇关于在数据库字段中存储数字数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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