How to store multiple values in single field in SQL database?

You could use a second table to store the numbers, and link back with a Foreign Key:

PersonTable: PersonId, Name, etc..

The second table will hold the numbers...

NumbersTable: NumberId, PersonId(fk), Number

You could then get the numbers like this...

SELECT p.Name, n.Number from PersonTable p Left Join NumbersTable n
on p.PersonId = n.PersonId

This is a simple example. I have used a LEFT JOIN here in case a person doesn't supply their number. Also, this is just pseudo code, so don't use Table in the name.


You should create separate tables for Person and PhoneNumber.

CREATE TABLE Person(PersonId int IDENTITY(1,1) PRIMARY KEY)

CREATE TABLE Phone(
    PersonId int,
    PhoneNumber varchar(20),
    CONSTRAINT PK_Phone PRIMARY KEY(PersonId,PhoneNumber),
    CONSTRAINT FK_PersonId FOREIGN KEY(PersonId) REFERENCES Person(PersonId)
    )

Tags:

Sql