Question

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 enter image description here

Edit:

Here is the new diagram

enter image description here

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top