How is a multi-valued attribute represented?

Asked

Viewed 5,430 times

0

I need to perform a modeling of Google Play as work of univerisdade, one of the requirements of the work is to represent a multivariate. how would that be represented? Would it be a type? ex:

Nome     Tipo
Genero   Set

in this case Set is a multivariate? If you can use some example involving google play will help.

2 answers

1

In multi-valued attributes database can be specific types such as an array, set, json etc. In most cases it is using a varchar (which usually indicates a problem in the modeling) such as for example in the posting system where the posts has a field of categoria which has as its value the identities of the categories separated by comma or any other delimiter.

Example:

id|titulo|categoria|data
1 |teste |1,2,49   |2018-04-19
2 |teste2|5        |2018-04-01
3 |teste3|22,6,78,3|2018-04-05

Related:

What is database normalization?

  • What would be the category type? varchar?

  • @Leonardofurtado in this example varchar, multivariate columns are evidas pq are complicated to search also need extra manipulation to update or validate the value.

1

Since your work is related to the Play Store, Género are "categories" of the store and these values are already stored in the database.

If the answer is yes, there is a problem of "many to many" and not just of "1 for many".

For a database to comply with the 1st Normal Form all table column values must be atomic in order to avoid data redundancy.

As such, the solution used for this problem involves the creation of an intermediate table to store the relationship between the two entities which assumes that the Categorias are previously defined would be something similar to this:

+---------+         +---------------------+        +-----------+
| EXEMPLO |         | EXEMPLO_CATEGORIA   |        | CATEGORIA |
+---------+ 1     * +---------------------+      1 +-----------+
|- ID [PK]|---------|- Exemplo [PK, FK]   |    +---|- ID [PK]  |
|- TITULO |         |- Categoria [PK, FK] |----+   |- Nome     |
|         |         |                     | *      |           |
|         |         |                     |        |           |
+---------+         +---------------------+        +-----------+

Either way I recommend reading the question What is database normalization? to get an idea of what the normal forms of a relational database and the best practices related to them are.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.