C
C
Carlyndow Marlifi2021-04-13 15:06:20
SQL
Carlyndow Marlifi, 2021-04-13 15:06:20

What data type should be used in sql to indicate genres for example?

If I want to put several different values ​​​​in 'genres' - action, thriller, drama, etc.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey Gornostaev, 2021-04-13
@petushok55

A many-to-many relationship is used in such cases.

S
Slava Rozhnev, 2021-04-13
@rozhnev

integer:

create table genres (
  	id int primary key auto_increment,
  	name varchar(255)
);

create table films (
  id int primary key auto_increment,
  	name varchar(255)
);

create table film_genres (
  film_id int,
  	genre_id int
);

SQL fiddle

L
longclaps, 2021-04-13
@longclaps

Look here .
Potentially not too much data to worry about the size of both the movie table and the genre table.

V
Vasily Bannikov, 2021-04-13
@vabka

In Postgresql, you can make an array of enams.
True, I xs how it will be with indexing.
The most common option is to make a table with genres and make a Many-to-Many relationship between it and the table with movies. It will be just another intermediate table with movie ID and genre ID.
Slava Rozhnev gave a code example for such a case..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question