Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to store a list of numbers in an SQL database?

Tags:

sql

database

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.

like image 981
Tyler Siegrist Avatar asked Feb 20 '23 02:02

Tyler Siegrist


1 Answers

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!)

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.

like image 134
Sergey Kalinichenko Avatar answered Feb 25 '23 10:02

Sergey Kalinichenko