SQL for movie database search engine

I am creating a movie database. Each film will have genres of genres, actors, directors, etc. Now my question is how can I create a database and write SQL, since each movie can have several actors or directors, etc.

Now my database design for the desktop movie is:

  • movie_id
  • MOVIE_TITLE
  • actors_id
  • directors_id
  • genre_id

But in this way, it seems more difficult to put several actors in the film.

+3
source share
4 answers

" " . , . "--" SQL, ( , ).

+-------------+
| Movie       |
+-------------+
| Id          |<----+
| Title       |     |
| Year        |     |
+-------------+     |
                    |
+-------------+     |
| Actor       |     |
+-------------+     |
| Id          |<-+  |
| Name        |  |  |
| Birthdate   |  |  |
+-------------+  |  |
                 |  |
+-------------+  |  |
| Movie_Actor |  |  |
+-------------+  |  |
| ActorId     |--+  |
| MovieId     |-----+
+-------------+

153:

SELECT Actor.Name
FROM Actor
JOIN Movie_Actor ON Movie_Actor.ActorId = Actor.Id
WHERE Movie_Actor.MovieId = 153
+8

. ( )

, , , , , , , .

, , movie_id movie_title, , , - MovieActors, movie_id actor_id. .

0

, , - . - , . :

Movie:: movie_id(primary key); movie_title;
Actor:: actor_id(primary key); actor_name; 
Appears_in:: movie_id(foreign key); actor_id(foreign_key)

Appears_in movie_id, actor_id / .

0

"", . , . , , , .. ..

, ( ). ? , , (.. "" , ).

What I'm saying, defining a scope can help you decide if your implementation is correct. Sit down and decide what exactly you use this project to then take the appropriate route (which is likely to be relational tables).

0
source

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


All Articles