Elegant database design support ... (MySQL / PHP)

I create a website for films ... I need to show information about each film, including genres, actors and a lot of information (IMDB.com) ...

I created a movie table, including an identifier and some basic information. For genres, I created a table of "genres" that includes 2 columns: ID and genre. Then I use the "genres2movies" table with two columns: movieID and genreID to join between genres and movie tables ...

Thus, for example, if a movie has 5 different genres, I get a movieID in 5 different rows of the "genres2movies" table. This is better than including a genre every time for every movie, but ...

There is a better way to do this.

I need to do this also for actors, languages, and countries, so performance and database size are really important.

Thanks!!!

+3
source share
3 answers

You are on the right track. It is a way to make many-to-many relationships. The size of the database will not grow much, because you use integers, and for speed you have to set the correct indexes for these identifiers. When executing SELECt queries, check EXPLAIN - this helps to find speed bottlenecks.

+5
source

It seems that you are following the right normalization rules at the moment, exactly what you want.

, , - , JOINs .

/

+6

- , .

, , , join (genres2movies) , , ( ) - .. , , , . , , , .

0

Source: https://habr.com/ru/post/1704574/


All Articles