drop database if exists movie_rentals;
create database movie_rentals;
use movie_rentals;
create table movie (
movie_id int,
title varchar(255),
release_year year,
length int,
rating enum('G','PG','PG-13','R','NC-17'),
category varchar(255),
primary key(movie_id)
);
create table actor (
actor_id int,
first_name varchar(255),
last_name varchar(255),
primary key(actor_id)
);
create table movie_actor (
movie_id int,
actor_id int,
primary key(movie_id, actor_id),
foreign key(movie_id) references movie(movie_id),
foreign key(actor_id) references actor(actor_id)
);
create table customer (
customer_id int,
first_name varchar(255),
last_name varchar(255),
address varchar(255),
postal_code varchar(255),
district varchar(255),
city varchar(255),
country varchar(255),
primary key(customer_id)
);
create table rental (
rental_id int,
customer_id int,
movie_id int,
rental_date datetime,
amount decimal(5,2),
primary key(rental_id),
foreign key(customer_id) references customer(customer_id),
foreign key(movie_id) references movie(movie_id)
);
My proposal:
I am not sure about the double line between movie and movie_actor. I tried to do some tests on MySQL to see if I could insert a movie without an actor on movie_actor table, but I couldn´t.
The columns you choose to be primary key won't be allowed to be NULL. So in this case movie_actor require that both movie_id and actor_id needs to be filled.
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.