0% found this document useful (0 votes)
2 views

SQL PROJECT(22BEECE004)

The document outlines a SQL project for a Movie Database Management System, detailing the creation and insertion of tables for movies, customers, tickets, and showtimes. It includes SQL commands for altering tables, performing aggregate functions, and executing various queries with joins and conditions. The project aims to efficiently manage movie-related operations such as ticket sales and customer information.

Uploaded by

taswanth7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL PROJECT(22BEECE004)

The document outlines a SQL project for a Movie Database Management System, detailing the creation and insertion of tables for movies, customers, tickets, and showtimes. It includes SQL commands for altering tables, performing aggregate functions, and executing various queries with joins and conditions. The project aims to efficiently manage movie-related operations such as ticket sales and customer information.

Uploaded by

taswanth7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

SQL PROJECT

Name:Aswanth.T
Dept:Third Year BE ECE
Reg.no:22BEECE004
Ttile:Movie Database Management System

Objective:

The goal of this project is to create a simple and efficient system to


manage key operations of a movie database, including movie details,
showtimes, ticket sales, and customer information, using a reliable
relational database system.

1. Table Creation:

Movies Table:

CREATE TABLE Movies (


MovieID INT AUTO_INCREMENT PRIMARY KEY,
Title VARCHAR(100) NOT NULL,
Genre VARCHAR(50) NOT NULL,
ReleaseYear INT NOT NULL,
Duration INT NOT NULL,
Rating DECIMAL(3, 1)
);

Customers Table:
CREATE TABLE Customers (
CustomerID INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
ContactNumber VARCHAR(15),
Address VARCHAR(255)
);

Tickets Table:

CREATE TABLE Tickets (


TicketID INT AUTO_INCREMENT PRIMARY KEY,
CustomerID INT NOT NULL,
MovieID INT NOT NULL,
ShowTime DATETIME NOT NULL,
Quantity INT NOT NULL,
TotalPrice DECIMAL(10, 2) NOT NULL
);

Showtime Table:

CREATE TABLE Showtimes (


ShowtimeID INT AUTO_INCREMENT PRIMARY KEY,
MovieID INT NOT NULL,
ShowTime DATETIME NOT NULL,
AvailableSeats INT NOT NULL
);

2. Table Insertion:

Movies Table:

INSERT INTO Movies (Title, Genre, ReleaseYear, Duration,


Rating)VALUES
('The Matrix', 'Sci-Fi', 1999, 136, 8.7),
('Inception', 'Action', 2010, 148, 8.8),
('Titanic', 'Romance', 1997, 195, 7.8);

Customers Table:

INSERT INTO Customers (Name, ContactNumber, Address) VALUES


('Arvind', '987-654-3210', 'Bengaluru, Karnataka'),
('Priya', '888-777-6666', 'Mumbai, Maharashtra'),
('Ravi', '777-666-5555', 'Chennai, Tamil Nadu');
Tickets Table:

INSERT INTO Tickets (CustomerID, MovieID, ShowTime, Quantity,


TotalPrice)
VALUES
(1, 1, '2025-01-15 18:00:00', 2, 2398.40),
(2, 2, '2025-01-16 20:30:00', 1, 1279.20),
(3, 3, '2025-01-17 17:00:00', 3, 3835.20);

Showtimes Table:

INSERT INTO Showtimes (MovieID, ShowTime,


AvailableSeats)VALUES
(1, '2025-01-15 18:00:00', 100),
(2, '2025-01-16 20:30:00', 150),
(3, '2025-01-17 17:00:00', 120);

3. ALTER and UPDATE the new column:

ALTER TABLE Movies ADD AvailableSeats INT DEFAULT 0;


UPDATE Movies SET AvailableSeats = 200 WHERE MovieID = 1;
UPDATE Movies SET AvailableSeats = 150 WHERE MovieID = 2;
UPDATE Movies SET AvailableSeats = 180 WHERE MovieID = 3;
Movies Table (after ALTER and UPDATE):

4. Aggregate Function with INNER JOINS (Total Revenue per


Movie):

SELECT m.Title AS MovieTitle, SUM(t.TotalPrice) * 80 AS


TotalRevenue
FROM Tickets t
INNER JOIN Movies m ON t.MovieID = m.MovieID
GROUP BY m.Title;

Output Table:

5. Joins (Inner Join of Four Tables):

SELECT c.Name AS CustomerName,m.Title AS MovieTitle,


t.Quantity,t.TotalPrice * 80 AS TotalPrice, t.ShowTime
FROM Tickets t
INNER JOIN Customers c ON t.CustomerID = c.CustomerID
INNER JOIN Movies m ON t.MovieID = m.MovieID
INNER JOIN Showtimes s ON t.MovieID = s.MovieID;

Output Table:
6. Wildcard Types:

SELECT Title FROM Movies WHERE Title LIKE 'I%';

Output Table:

7. COUNT( ) TotalTickets using GROUP BY( ):

SELECT m.Title, COUNT(t.TicketID) AS TotalTickets


FROM Movies m
LEFT JOIN Tickets t ON m.MovieID = t.MovieID
GROUP BY m.Title;

Output Table:

8. WHERE condition with GROUP BY:


SELECT MovieID, COUNT(ShowtimeID) AS TotalShowtimes
FROM Showtimes
WHERE AvailableSeats > 100
GROUP BY MovieID;

Output Table:

9. BETWEEN and AND:

SELECT Title, Duration FROM Movies


WHERE Duration BETWEEN 120 AND 180;

Output Table:

10. DELETE( ) a row in Table:

DELETE FROM Movies WHERE Rating < 7;

Output Table:

You might also like