Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing multiple values for a single field in a database

Suppose i have a table with 3 fields

Person_id, Name and address. Now the problem is that a person can have multiple addresses. and the principle of atomic values says that data should be atomic.

So then how am i suppose to store multiple addresses for a single person ?

like image 300
Some Body Avatar asked May 13 '12 15:05

Some Body


People also ask

Can a database column have multiple values?

In most database systems you can store only a single value in a field. But in Access, you can also create a field that holds multiple values (up to 100). For example, you want to track employees working on issues.

How can I add multiple values in one column in SQL?

Thus, we can use INSERT-SELECT-UNION query to insert data into multiple rows of the table. The SQL UNION query helps to select all the data that has been enclosed by the SELECT query through the INSERT statement.

Can a column have multiple values in SQL?

In SQL, for matching multiple values in the same column, we need to use some special words in our query. Below, 3 methods are demonstrated to achieve this using the IN, LIKE and comparison operator(>=). For this article, we will be using the Microsoft SQL Server as our database.

Which SQL operator is used to give the multiple values for a single field at a time?

The IN operator allows you to specify multiple values in a WHERE clause.


1 Answers

You're supposed to create an ADDRESS table that has a foreign key linking it to a PERSON record, i.e. PERSON_ID. This is the "relational" component of a relational database, and it's why it's more flexible than a flat file (which is like a single table).

like image 195
Marc Avatar answered Sep 18 '22 00:09

Marc