Split column into multiple tables

Asked

Viewed 344 times

7

I want to save a set of information about movies in a database but I have a question, I must organize the genres in column (example below).

inserir a descrição da imagem aqui

Database: Mysql 5.6.21

Engine: innoDB

or organize gender in a separate table and use a third table for relationships?

using the first way I can select using LIKE.

  • 1

    Because the downvote?

2 answers

8

The two ways are possible. The most traditional is to use an extra table and normalize the gender register. This is the way normalized. In general you need to have a good reason to not normalize.

In any of the solutions, the ideal is to have a table with descriptions of the genders. And then you only use the ID of them. Be in the column of Generos of your table Videos, be on the X film binding table genres - the most recommended way.

If you still want to keep a list of genders in the column, you can see a question that I made of how to index this.

You’d probably have the tables:

Videos

Id
Titulo
Duracao

Generous

Id
Descricao

Videosxgeneros

Id
VideoId
GeneroId
  • This way simplifies and greatly the sqls.

7


I suggest using this way:

Modelo Relacional

So you can get full control of the movies by genre, how many action films you own, how many action films and comedy you have, using just one JOIN.

Browser other questions tagged

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