简体   繁体   中英

SQL movie database diagram

Im working on a small school project where im creating a movie database in SQL. I've created the tables and was wondering if I will encounter any problems with the model i created.

Thanks in advance.

Current diagram 在此处输入图片说明

Edit:

Here is the new diagram

在此处输入图片说明

MovieDetails is bad design. You need one row in MovieDetails per actor, while the director will be the same, which is data duplication. Instead, the Movie table should have a foreign key referencing director, then a MovieActor table should represent the many to many relationship between movies and actors.

Technically, there's also no reason to have different tables for Directors and Actors since you have the same data in the tables. You could just as well have a Person table with both.

How about (I am only showing the relevant columns)

movie table
-----------
id
title


person
------
id
name


cast table
----------
movie_id
person_id
movie_role_id (actor, director, ...)


role_type table
----------------
id
name   (actor, director, ...)


genres table
------------
id
name


movie_genres table
------------------
movie_id
genre_id

I would consider the following structure:

movie(id, title, year, rating, plot, length)

actor(id, first name, last name, nationality, birth_date)
director(id, first name, last name, nationality, birth_date)

movie_x_actor(movie_id, actor_id)
movie_x_director(movie_id, director_id)

This is, of course, just the simplest example. You can, for instance add a movie_series table like:

movie_series(id, title)

movie_x_movie_series(movie_id, series_id, plot_order_number)

and, like @Juergen described, a movie usually belongs to more than one genre so:

genres(id, genre_name, genre_description)
movie_x_genres(movie_id, genre_id)

You should definitely take a look at one-to-many and many-to-many relationships between rows in tables .

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM