在SQL数据库中存储数字列表的最佳方式? [英] Best way to store a list of numbers in an SQL database?

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

问题描述

我需要存储一个数字列表,最好是一个单元格。我有一个人的列表,每个人都有一个唯一的ID,我需要能够他们的家庭成员是谁。

I need to store a list of numbers, preferably into a single cell. I have a list of people each with a unique ID and I need to be able to who their family members are. I'm fairly new to SQL databases to try to keep it fairly simple please.

推荐答案

不要这样做:存储多个值在单个列中杀死了使用引用完整性约束的可能性,并变成了一个噩梦来维护(想象一下,当一个新生的婴儿出生时,维护每个人的列表!)

Do not do this: storing multiple values in the single column kills the possibility of using referential integrity constraints, and turns into a nightmare to maintain (imagine maintaining everyone's lists when a new baby's born!)

最简单的解决方案是向每个人的行添加一个 family_id 的列。同一系列的所有成员都将此唯一ID设置为相同的值;不同家庭的成员将有不同的 family_id

The simplest solution is to add a column with a family_id to each person's row. All members of the same family will have this unique ID set to the same value; members of different families will have different family_ids.

这不是理想的婚姻情况,除非你愿意在子女结婚时加入两个家庭,或将新娘或新郎移送到配偶的家庭。

This is not ideal in cases of marriages, unless you are willing to either join the two families on marriage of their children, or move the bride or the groom to the family of the spouse.

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

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