DBMS Ca2
DBMS Ca2
Harsh
Question 1: Understanding Data Model (Sakila DB) - (10 marks)
The Sakila database is set up to show how a DVD rental store runs,
with different tables storing details about movies, customers, staff,
and transactions. At the heart of it is the film table, which holds
info about each movie and connects to the film_actor and
film_category tables—this way, a movie can have several actors and
belong to different genres. The inventory table keeps track of which
physical copies of movies are available at each store, linking each
copy to both the store and the film.When someone rents a movie,
it gets recorded in the rental table, which ties together the specific
movie copy, the customer, and the staff member who helped them.
Customer details live in the customer table, which also links each
person to their address and the store they usually go to. Payments
are recorded in the payment table, which connects each payment
to the rental, the customer, and the staff involved.Each table has its
own unique ID—like film_id or rental_id—to keep things organized,
and foreign keys are used to connect the tables properly. Overall,
the Sakila database is neatly put together and helps manage
everything from movies and rentals to payments and customer info
across different store locations.
Explain the relationship between the film, inventory, and rental tables.
Why is the inventory table necessary instead of directly linking rental to film?
Provide a brief explanation of how these tables interact.
In the Sakila database, the film, inventory, and rental tables work closely together to keep track of how movies are stored and
rented out. The film table holds the basic details about each movie—like its title, description, release year, and language—but
it doesn’t say anything about how many copies there are or where they’re located.
That’s where the inventory table steps in. It acts like a link between the films and the rentals by representing each physical
DVD available in a store. Each record in the inventory table connects a specific film to a specific store, which helps manage
multiple copies of the same movie across different store locations. Without it, there’d be no way to know which store has
which movies or how many copies are actually available.Then there’s the rental table, which logs every rental transaction.
Instead of pointing directly to a film, it links to the inventory table. This setup allows the system to keep track of exactly which
copy of a movie was rented, from which store, and when. It’s a smart and practical way to handle rentals, returns, and stock
management—just like you’d need in a real DVD rental business.
4) A customer wants to rent a movie, but the movie is currently out ofstock.Describe how you would query the database to
check when a copy of that movie will be available for the next rental.
7. Describe a normalization issue that might arise if the payment table stored film details directly instead of referencing
rental_id. How does the current design prevent data redundancy?
If the payment table included film details directly, it would end up repeating the same information over and over. Every time
someone made a payment for a rental, things like the movie’s title or description would have to be stored again. That kind of
repetition not only wastes space but also makes the database messy and harder to maintain.This goes against the idea of
normalization, which is all about keeping the data clean, organized, and free of unnecessary duplication. Instead, the way the
database is currently set up is much smarter—each payment is linked to a rental using the rental_id, and that rental already
connects to the right film through the inventory table.Thanks to this setup, movie details are only saved once in the film table,
and everything else just refers back to it. That makes the database more efficient, easier to update, and less likely to have errors
or mismatched information. It’s a cleaner, more reliable way to handle things.
Question 2
1.Write a 150-200 word summary explaining the key tables and their relationships.
The Sakila database is built to handle everything you'd expect in a movie rental business. It uses a bunch of connected tables to
keep all the data organized and easy to manage.The customer table stores details about each customer—like their name, contact
info, and the store they’re associated with. Each customer is linked to an address, which then connects to the city and country
tables. This setup helps keep location data neat and avoids repeating the same info over and over.
3. Write an SQL query to find customers who have not rented any movie in the last 180 days.
4. Write an SQL query to retrieve all customers who have overdue rentals, including their names,rentaldates,and duedates.
6. Write an SQL query to find the top 3 most rented movie categories and the total number of rentals for each.
Question 3
1. Write a 150-200 word summary explaining the key tables and their relationships.
The Sakila database relies on six key tables to manage movie rentals: film, inventory, rental, customer, staff, and payment. Each
of these tables has a primary key (PK) that uniquely identifies each record, and foreign keys (FKs) that connect related
information across tables.The film table holds all the details about each movie and uses film_id as its primary key. Since a single
movie can have multiple physical copies, those are tracked in the inventory table. The inventory table has its own inventory_id
as a primary key and uses film_id as a foreign key to show which film each copy belongs to.Whenever a customer rents a
movie, that action is logged in the rental table. Each rental gets a unique rental_id and is linked to an inventory item, a
customer, and a staff member using foreign keys. The customer and staff tables store personal details of the people involved,
each identified by their own unique IDs.Payments are handled in the payment table, which tracks how much was paid for each
rental. This table links each payment back to the specific rental, the customer who paid, and the staff member who processed
it using foreign keys.All these connections help keep the data organized, accurate, and easy to work with—making it simple to
track everything from movie details to who rented what and how much they paid.
2. Write an SQL query to find customers who have returned movies late more than 3 times.
After analyzing the Sakila database, it was found that Mike Hillyer has processed the highest number of
rentals among the staff members. He completed a total of 8040 rentals, making him the top performer. His
activity level is slightly higher than his colleague, showing strong involvement in daily rental transactions.
This
information is essential for recognizing individual contributions and evaluating employee performance.
3. Write an SQL query to find the top 5 customers who have rented the most
4. Write an SQL query to find the total number of rentals handled by each staff member, sorted from highest to lowest.
Thank You