You are on page 1of 34

UNIVERSITY OF COMPUTER STUDIES, YANGON

Software Engineering Project

Automobile Project

Covered By
Fundamental Database Management System

Faculty of Information Science

University of Computer Studies, Yangon


Submitted By
Group No - 3
August, 2023

1
Group – 3

Roll No Name Role


YKPT-22316 Naing Aung Linn Documenting Project
YKPT-22355 Thurein Htet Documenting Project
YKPT-22319 Nyan Min Htet Entity Relationship Diagram
YKPT-22352 Thura Aung Presentation
YKPT-22366 Thuta Nyan Creating Tables
YKPT-22333 Aung Kaung Myat Generating relational algebra
YKPT-22334 Kaung Khant Linn Generating queries
YKPT-22359 Lin Pyae Bo Creating Tables

2
Contents
Chapter 1: Introduction
1.1: Project Description
1.2: Project Objectives
Chapter 2: Database Management System
2.1: Entity Relationship (ER) Diagram
2.2: Data Dictionary
2.3: Data Insertion in Relational Tables
2.4: Customer Requirements
2.5: Query Planning with Algebra
2.6: Query Execution with MySQL
Chapter 3: Conclusion

3
Chapter-1
Introduction

1.1 Project Description


The Automobile database system include 13 entities, and application for this database system is
for a fictitious automobile company which needs to keep track of various data, from vehicle
information, manufacturing plants to retailers and customer information. Entities included in this
database include:
- Vehicles
- Models
- Brand
- Options
- Model-Options
- Dealers
- DealerPurchase
- Suppliers
- Company
- Company-owned manufacturing plants
- ManufacturedBrand
- Customers
- Purchase
This system should be able to produce queries useful for the company, such as showing the top
selling brands over the span of two years, or in which months do certain types of cars sell best to
cater to customers’ need and to maximize profit.

1
1.2 Project Objectives

Conceptual Design – creating an Entity Relationship Diagram (ERD) which accurately


depicts entities and attributes as well as keys and cardinalities.
Relational Model – create a relational database model with relevant tables in MySQL in
accordance with the ER diagram.
Data Population – populate the tables with relevant and sufficient amount of data.
Despite the data not being ‘realistic’, they should allow us to make meaningful queries.
Query Implementation – producing queries that might also be applicable in the real
world. The queries will include complex database operations such as Nested Queries,
Joins, Aggregate Functions and Conditional Aggregations, Date and Time
manipulations, and Multi-Table Filtering.
Documentation – producing a comprehensive documentation for each and every section
of the project including design decisions to query generations and procedures.

2
Chapter-2
Database Management System

2.1 Entity Relationship Diagram


An Entity Relationship Diagram (ERD) is a blue-print or visual representation of
the entities, attributes and the cardinalities between the entities. The ER diagram assists
in the making of the logical design and makes communication between group members
easier, as it ensures everyone has common understanding of the model design.

3
4
2.2 Data Dictionary

Entity Name: Vehicle


Primary Key: VehicleID
Foreign Key: BrandID, ModelID
Attribute Name Data Types Size Description
VehicleID (PK) VARCHAR 10 Unique Identification Number for
vechicles
BrandID (FK) VARCHAR 10 Brand Identification Number of the
vehicle
ModelID (FK) VARCHAR 10 Model Identification Number of the
vehicle
VehicleLiscense VARCHAR 15 License of the vehicle
ManufactureYear INT - Manufacture date for the vechicle

Price INT - Vehicle Price

Entity Name: Customers


Primary Key: CustomerID
Foreign Key: -
Attribute Name Data Types Size Description
CustomerID (PK) VARCHAR 20 Unique Identification Number for
customer
CustomerEmail VARCHAR 45 Customer email
CustomerName VARCHAR 55 Names of the customer
CustomerPhone VARCHAR 20 Customer Phone Number
Gender VARCHAR 10 Customer Gender

Income INT - Annual income of the customer

Entity Name: Dealers


Primary Key: DealersID
Foreign Key: -
Attribute Name Data Types Size Description
DealersID (PK) VARCHAR 10 Unique Identification Number for dealers
DealerEmail VARCHAR 30 Dealer email
DealerName VARCHAR 30 Names of the dealer
DealerPhone VARCHAR 20 Dealer Phone Number
Location VARCHAR 15 Location of the dealer

5
Entity Name: Suppliers
Primary Key: SuppilerID
Foreign Key: -
Attribute Name Data Types Size Description
SuppilerID (PK) VARCHAR 10 Unique Identification Number for
suppliers
SuppilerEmail VARCHAR 30 Supplier email
SuppilerName VARCHAR 30 Names of the supplier
SuppilerPhone VARCHAR 20 Supplier Phone Number
Suppilerlocation VARCHAR 15 Location of the supplier

Typesofsupplies VARCHAR 30 Available type of supplies

Entity Name: Brands


Primary Key: BrandID
Foreign Key: CompanyID
Attribute Name Data Types Size Description
BrandID VARCHAR 10 Unique Identification Number for Brands
BrandName VARCHAR 15 Name of the Brand
CompanyID VARCHAR 15 Identification Number of the Company

Entity Name: ModelOption


Primary Key: ModelID, OptionID
Foreign Key: ModelID, OptionID
Attribute Name Data Types Size Description
ModelID (FK, PK) VARCHAR 10 Composite Identification for model
OptionID (FK, PK) VARCHAR 10 Composite Identification for option

Entity Name: Companies


Primary Key: CompaniesID
Foreign Key: -
Attribute Name Data Types Size Description
CompanyID (PK) VARCHAR 15 Unique Identification Number for
Company
CompanyName VARCHAR 30 Company Name

6
Entity Name: Model
Primary Key: ModelID
Foreign Key: BrandID
Attribute Name Data Types Size Description
ModelID (PK) VARCHAR 10 Unique Identification Number for Model
ModelName VARCHAR 15 Name of the Model
BrandID (FK) VARCHAR 10 Identification Number for Brands
Vehiclestyle VARCHAR 20 The style of the vehicle
CountryOfOrigin VARCHAR 20 Country of origin

ReleaseYear INT - Released year for the model

Entity Name: Option


Primary Key: OptionID
Foreign Key: -
Attribute Name Data Types Size Description
OptionID (PK) VARCHAR 10 Unique Identification for vehicle option
Color VARCHAR 20 Color option of the vehicle
EngineModel VARCHAR 40 Engine model
FuelType VARCHAR 10 Type of Fuel
HorsePower INT - Horse Power of the engine in the vehicle

Transmission VARCHAR 30 Transmission type of the vehicle

Convertible BOOLEAN - Indication if the vehicle is convertible or


not

Entity Name: DealerPurchase


Primary Key: VehicleID, DealerID
Foreign Key: VehicleID, DealerID
Attribute Name Data Types Size Description
VechicleID (PK, FK) VARCHAR 10 Identification Number for manufacturing
plant
DealerID (PK, FK) VARCHAR 10 Identification Number for Dealer
SupplyTimeInDays INT - Waiting time for the Supply (in days)
Units INT - Number of units purchased

7
Entity Name: Purchase
Primary Key: PurchaseID
Foreign Key: CustomerID, DealersID
Attribute Name Data Types Size Description
PurchaseID (PK) VARCHAR 10 Unique Identification Number for Customer
Purchases
CustomerID (FK) VARCHAR 20 Identification Number for Customer
DealersID (FK) VARCHAR 10 Identification Number for Dealer
VehicleID (FK) VARCHAR 10 Identification Number for Vehicle
PurchaseDate DATE - Date on which the purchase is made
PaymentMethod VARCHAR 10 Payment Method for the purchase
Quantity INT - Number of vehicles purchased
TotalPrice INT - Total price of the purchase

Entity Name: ManufacturedBrand


Primary Key: ManufacturedBrandID
Foreign Key: Manufacture_ID, BrandID, SupplierID
Attribute Name Data Types Size Description
ManufacturedBrandID (PK) VARCHAR 10 Unique Identification Number for
ManufacturedBrand
Manufacture_ID (FK) VARCHAR 10 Identification Number for Manufacturing Plant
BrandID (FK) VARCHAR 10 Identification Number for Brand
SupplierID (FK) VARCHAR 10 Identification Number for Supplier
SupplyDate DATE - Date of the Supply

Entity Name: CompanyOwnedManufacturingPlants


Primary Key: Manufacture_ID
Foreign Key: CompanyID
Attribute Name Data Types Size Description
Manufacture_ID (PK) VARCHAR 10 Unique Identification Number for manufacturing
plant
ManufacturingPlantsName VARCHAR 20 Manufacturing Plant Name
CompanyID (FK) VARCHAR 15 Identification Number for Company
PlantLocation VARCHAR 30 Location of the manufacturing plant

8
2.3 Data Insertion in Relational Tables

Vehicle Table data

Create table code


Create Table Vehicle (

VehicleID varchar(10) not NULL,

BrandID varchar(10),

ModelID varchar(10),

VehicleLiscense varchar(15),

ManufactureYear int,

Price int,

Primary key (VehicleID),

Foreign key(BrandID) references Brands(BrandID),

Foreign key(ModelID) references Models(ModelID)

);

Insert code

INSERT INTO Vehicle (VehicleID, BrandID, ModelID, VehicleLiscense, ManufactureYear, Price)

VALUES

('V-1','B-3','M-1','O6-6604',2005,4300000), ('V-2','B-3','M-1','T5-4401',2013,6600000),

('V-3','B-1','M-2','I2-9653',2016,4400000), ('V-4','B-5','M-3','Q9-9887',2009,9100000),

('V-5','B-1','M-4','N6-3555',2005,8000000), ('V-6','B-5','M-5','F9-7178',2017,8300000),

('V-7','B-4','M-6','X5-3831',2020,4500000), ('V-8','B-1','M-7','E2-6149',2009,6900000),

('V-9','B-4','M-8','W9-6118',2006,4800000), ('V-10','B-4','M-9','X3-6935',2001,3700000),

('V-11','B-1','M-10','B2-4402',2013,9500000), ('V-12','B-2','M-11','H9-4994',2020,8800000),

('V-13','B-3','M-2','P1-9115',2011,9700000), ('V-14','B-4','M-9','V9-8123',2013,5300000),

('V-15','B-4','M-11','Z9-7737',2011,8900000),('V-16','B-5','M-5','F4-5841',2004,8700000),

('V-17','B-5','M-7','Z7-3489',2019,4200000), ('V-18','B-1','M-8','G5-7151',2020,6400000),

('V-19','B-5','M-9','L3-7459',2008,8400000),('V-20','B-3','M-10','E4-9840',2002,7400000),

('V-21', 'B-2', 'M-5', 'D9-1234', 2015, 5500000),('V-22', 'B-3', 'M-6', 'E8-5678', 2019, 7000000),

('V-23', 'B-6', 'M-8', 'F7-4321', 2014, 6000000),('V-24', 'B-1', 'M-2', 'G6-8765', 2017, 7500000),

('V-25', 'B-4', 'M-4', 'H5-3456', 2018, 8000000),('V-26', 'B-6', 'M-10', 'J3-9876', 2016, 6500000),

9
('V-27', 'B-2', 'M-11', 'K2-6543', 2017, 9000000),('V-28', 'B-3', 'M-1', 'L1-2345', 2018, 8500000),

('V-29', 'B-5', 'M-7', 'M0-7654', 2019, 9500000), ('V-30', 'B-6', 'M-3', 'N9-8765', 2020, 10000000);

Customer Table Data

Create table code

CREATE TABLE Customers(

CustomerID VARCHAR(20) primary key not null,

CustomerEmail VARCHAR(45),

CustomerName VARCHAR(55),

CustomerPhone VARCHAR(20),

Gender varchar(10),

Income int

);

Insert code
INSERT INTO Customers (CustomerID, CustomerEmail, CustomerName, CustomerPhone,
Gender, Income) VALUES
('C-1', 'JohnSmith@example.com', 'John Smith', '+1-123-456-7890', 'Male', 500000),
('C-2', 'JaneJohnson@example.com', 'Jane Johnson', '+1-234-567-8901', 'Female', 600000),
('C-3', 'MichaelWilliams@example.com', 'Michael Williams', '+1-345-678-9012', 'Male', 750000),
('C-4', 'EmilyBrown@example.com', 'Emily Brown', '+1-456-789-0123', 'Female', 550000),
('C-5', 'DavidJones@example.com', 'David Jones', '+1-567-890-1234', 'Male', 700000),
('C-6', 'SarahSmith@example.com', 'Sarah Smith', '+1-678-901-2345', 'Female', 600000),
('C-7', 'JohnJohnson@example.com', 'John Johnson', '+1-789-012-3456', 'Male', 650000),
('C-8', 'JaneWilliams@example.com', 'Jane Williams', '+1-890-123-4567', 'Female', 800000),
('C-9', 'MichaelBrown@example.com', 'Michael Brown', '+1-901-234-5678', 'Male', 550000),
('C-10', 'EmilyJones@example.com', 'Emily Jones', '+1-012-345-6789', 'Female', 700000),
('C-11', 'DavidSmith@example.com', 'David Smith', '+1-123-456-7890', 'Male', 600000),
('C-12', 'SarahJohnson@example.com', 'Sarah Johnson', '+1-234-567-8901', 'Female', 750000),
('C-13', 'JohnWilliams@example.com', 'John Williams', '+1-345-678-9012', 'Male', 550000),
('C-14', 'JaneBrown@example.com', 'Jane Brown', '+1-456-789-0123', 'Female', 700000),
('C-15', 'MichaelJones@example.com', 'Michael Jones', '+1-567-890-1234', 'Male', 600000),
('C-16', 'Chris@example.com', 'Chris', '+1-154-531-8753', 'Male', 75000),
('C-17', 'Rebacca@example.com', 'Rebacca', '+1-348-967-8759', 'Female', 550000),
('C-18', 'Jonas@example.com', 'Jonas', '+1-425-804-2134', 'Male', 700000);

10
Dealer Table Data

Create table code

Create table Dealers

DealersID varchar(10) primary key not null,

DealerEmail varchar(30),

DealerName varchar(30),

DealerPhone varchar(20),

Location varchar(15)

);

Insert code

INSERT INTO Dealers (DealersID, DealerEmail, DealerName, DealerPhone, Location)

VALUES

('D-1', 'john@example.com', 'John''s Auto Parts', '555-123-4567', 'Cityville'),

('D-2', 'smith@example.com', 'Smith''s Motors', '555-987-6543', 'Townsville'),

('D-3', 'autohaven@example.com', 'Auto Haven', '555-555-5555', 'Villageburg'),

('D-4', 'carworld@example.com', 'Car World', '555-222-3333', 'Metropolis'),

('D-5', 'motormart@example.com', 'Motor Mart', '555-888-9999', 'Suburbia');

11
Supplier Table Data

Create table code

Create table Suppliers

SuppilerID varchar(10) primary key not null,

SuppilerEmail varchar(30),

SuppilerName varchar(30),

SuppilerPhone varchar(20),

Suppilerlocation varchar(15),

Typesofsupplies varchar(30)

);

Insert code

INSERT INTO Suppliers (SuppilerID, SuppilerEmail, SuppilerName, SuppilerPhone,


Suppilerlocation, Typesofsupplies)

VALUES

('S-1', 'partrus@example.com', 'Parts R Us', '555-111-2222', 'Industrial City', 'Auto


Parts'),

('S-2', 'cartech@example.com', 'CarTech Supplies', '555-333-4444', 'Tech Town', 'Car


Electronics'),

('S-3', 'engineparts@example.com', 'Engine Parts Inc.', '555-777-8888', 'Mechanicville',


'Engine Components'),

('S-4', 'tireworld@example.com', 'Tire World', '555-555-6666', 'Rubber Town', 'Tires'),

('S-5', 'glowauto@example.com', 'Glow Auto', '555-666-7777', 'Luminous City', 'Head


Lights'),

('S-6', 'Getrag@example.com', 'Getrag', '555-777-8888', 'Elegance City',


'Transmissions'),

('S-7', 'autopaints@example.com', 'ColorBlend Auto Paints', '555-444-5555',


'Paintsville', 'Automotive Paints');

12
Brand Table Data

Create table code

CREATE TABLE Brands (

BrandID VARCHAR(10) PRIMARY KEY NOT NULL,

BrandName VARCHAR(15) NOT NULL,

CompanyID VARCHAR(15),

FOREIGN KEY(CompanyID) REFERENCES Companies(CompanyID)

);

Insert code

INSERT INTO Brands(BrandID, BrandName, CompanyID)

VALUES

('B-1', 'Toyota', 'TM'),

('B-2', 'Honda', 'HMC'),

('B-3', 'Chevrolet', 'GM'),

('B-4', 'Ford', 'FORD'),

('B-5', 'BMW', 'BMW'),

('B-6', 'Bentley', 'VW');

13
Models Table Data

Create table code

CREATE TABLE Models (

ModelID varchar(10) PRIMARY KEY NOT NULL,

ModelName varchar(15),

BrandID varchar(10),

Vehiclestyle varchar(20),

CountryOfOrigin varchar(20),

ReleaseYear int,

FOREIGN KEY (BrandID) REFERENCES Brands(BrandID)

);

Insert code

INSERT INTO Models VALUES

('M-1', 'Toyota Avalon', 'B-1', 'Sedan', 'U.S.A', 2022),

('M-2', 'Honda CR-V', 'B-2', 'SUV', 'U.S.A', 2018),

('M-3', 'Land Cruiser', 'B-1', 'Crossover', 'Japan', 2020),

('M-4', 'Civic', 'B-2', 'Sedan', 'Japan', 2022),

('M-5', 'Impala', 'B-3', 'Sedan', 'U.S.A', 2021),

('M-6', 'Camaro', 'B-3', 'Coupe', 'U.S.A', 2022),

('M-7', 'Focus', 'B-4', 'Hatchback', 'U.S.A', 2021),

('M-8', 'Explorer', 'B-4', 'SUV', 'U.S.A', 2022),

('M-9', 'X3', 'B-5', 'SUV', 'Germany', 2022),

('M-10', '3 Series', 'B-5', 'Sedan', 'Germany', 2022),

('M-11','Bentayga Azure','B-6','SUV','Germany',2015);

14
Options Table Data

Create table code

CREATE TABLE Options (

OptionID VARCHAR(10) PRIMARY KEY NOT NULL,

Color VARCHAR(20),

EngineModel VARCHAR(40),

FuelType VARCHAR(10),

HorsePower INT,

Transmission VARCHAR(30),

Convertible BOOLEAN NOT NULL DEFAULT FALSE

);

Insert code

INSERT INTO Options (OptionID, Color, EngineModel, FuelType, HorsePower, Transmission,


Convertible) VALUES

('O-1','Red','2.0L Alpha','Gasoline',150,'Manual', TRUE),

('O-2','Blue','3.5L V6 Zeta','Gasoline',275,'Automatic', FALSE),

('O-3','Gray','2.0L Alpha Hybrid','Hybrid',155,'Automatic', TRUE),

('O-4','PaleBlue','2.5L Beta Diesel','Diesel',180,'Automatic', FALSE),

('O-5','Silver','3.5L V6 Zeta','Gasoline',280,'Automatic', TRUE),

('O-6','Red','2.4L Iota','Gasoline',180,'Manual', FALSE),

('O-7','Silver','3.0L Gamma Diesel','Diesel',200,'Manual', FALSE),

('O-8','Red','2.0L Epsilon Electric','Electric',180,'Automatic', FALSE),

('O-9','White','2.4L Iota','Gasoline',180,'Automatic', FALSE),

('O-10','Green','2.0L Alpha','Gasoline',150,'Automatic', TRUE),

('O-11','Red','1.6L Turbo Kappa','Gasoline',175,'Automatic', FALSE),

('O-12','Blue','2.5L Beta','Gasoline',170,'Manual', TRUE),

('O-13','Green','2.5L Epsilon Electric','Electric',190,'Automatic', FALSE),

('O-14','Green','3.0L V6 Lambda','Gasoline',250,'Automatic', FALSE),

('O-15','Golden','1.6L Pi Turbo','Gasoline',178,'Manual', FALSE);

15
ModelOption Table Data

Create table code

Create table ModelOption

ModelID varchar(10) NOT NULL,

OptionID varchar(10) NOT NULL,

FOREIGN KEY (ModelID) REFERENCES Models(ModelID),

FOREIGN KEY (OptionID) REFERENCES Options(OptionID),

Primary Key(ModelID,OptionID)

);

Insert code

INSERT INTO ModelOption (ModelID, OptionID) VALUES

('M-1', 'O-1'), ('M-1', 'O-2'), ('M-1', 'O-3'),('M-1', 'O-4'),('M-1', 'O-5'),('M-2', 'O-10'),

('M-2', 'O-12'), ('M-2', 'O-3'), ('M-2', 'O-4'), ('M-2', 'O-5'), ('M-3', 'O-11'), ('M-3', 'O-12'),

('M-3', 'O-8'), ('M-3', 'O-4'),('M-3', 'O-15'), ('M-4', 'O-1'),('M-4', 'O-2'), ('M-4', 'O-13'),

('M-4', 'O-4'),('M-4', 'O-5'), ('M-5', 'O-1'),('M-5', 'O-2'), ('M-5', 'O-3'), ('M-5', 'O-6'),

('M-5', 'O-5'), ('M-6', 'O-1'),('M-6', 'O-2'), ('M-6', 'O-3'), ('M-6', 'O-4'), ('M-6', 'O-7'),

('M-7', 'O-14'), ('M-7', 'O-15'), ('M-7', 'O-11'), ('M-8', 'O-9'), ('M-8', 'O-10'), ('M-8', 'O-12'),

('M-8', 'O-3'),('M-9', 'O-4'), ('M-9', 'O-8'),('M-9', 'O-11'),('M-10', 'O-7'), ('M-10', 'O-9'),

('M-10', 'O-10'), ('M-11', 'O-1'), ('M-11', 'O-3'),('M-11', 'O-8'), ('M-11', 'O-10'),('M-11', 'O-13');

16
Companies Table Data

Create table code

Create table Companies

CompanyID VARCHAR(15) not null Primary Key,

CompanyName VARCHAR(30)

);

Insert code

INSERT INTO Companies (CompanyID, CompanyName)

VALUES ('GM', 'General Motors'),

('VW', 'Volkswagen Group'),

('TM', 'Toyota Motor Corporation'),

('HMC', 'Honda Motor Co., Ltd.'),

('FORD', 'Ford Motor Company'),

('BMW', 'BMW Group');

17
CompanyOwnedManufacturingPlants Table Data

Create table code

Create table CompanyOwnedManufacturingPlants

ManufactureID varchar(10),

ManufacturingPlantsName varchar(20),

CompanyID varchar(15),

PlantLocation varchar(30),

primary key (Manufacture_ID),

foreign key(CompanyID)references Companies (CompanyID)

);

Insert code

INSERT INTO CompanyOwnedManufacturingPlants (ManufactureID,

ManufacturingPlantsName, CompanyID, PlantLocation)

VALUES ('JTD', 'Toyota', 'TM', 'Japan'),

('JHM', 'Honda', 'HMC', 'United States'),

('1GN', 'Chevrolet', 'GM', 'United States'),

('1FA', 'Ford', 'FORD', 'Europe'),

('WBA', 'BMW', 'BMW', 'Europe'),

('SVS', 'Bentley', 'VW', 'United Kingdom');

18
DealerPurchase Table Data

Create table code

Create table DealerPurchase

VehicleID varchar(10),

DealersID varchar(10),

SupplyTimeInDays int,

Units int,

Foreign Key (VehicleID) References Vehicle(VehicleID),

Foreign Key (DealersID) References Dealers(DealersID),

Primary Key(VehicleID,DealersID)

);

Insert code

INSERT INTO DealerPurchase (VehicleID, DealersID, SupplyTimeInDays, Units)

VALUES

('V-1', 'D-1', '100', '1'), ('V-2', 'D-2', '60', '1'), ('V-3', 'D-3', '211', '4'),

('V-4', 'D-4', '156', '2'), ('V-5', 'D-5', '90', '2'), ('V-6', 'D-4', '75', '1'),

('V-7', 'D-3', '78', '2'), ('V-8', 'D-2', '30', '1'), ('V-9', 'D-1', '98', '2'),

('V-10', 'D-5', '69', '1'), ('V-11', 'D-1', '166', '1'), ('V-12', 'D-2', '249', '5'),

('V-13', 'D-3', '101', '2'), ('V-14', 'D-4', '57', '1'), ('V-15', 'D-4', '109', '4'),

('V-16', 'D-5', '39', '1'), ('V-17', 'D-4', '244', '3'), ('V-18', 'D-1', '10', '1'),

('V-19', 'D-2', '40', '1'), ('V-20', 'D-2', '18', '1'), ('V-21', 'D-3', '158', '1'),

('V-22', 'D-4', '183', '8'), ('V-23', 'D-5', '203', '1'), ('V-24', 'D-5', '91', '1'),

('V-25', 'D-1', '105', '7'), ('V-26', 'D-4', '55', '1'), ('V-27', 'D-3', '69', '1'),

('V-28', 'D-5', '122', '2'), ('V-29', 'D-4', '198', '3'), ('V-30', 'D-3', '287', '5');

19
Purchase Table Data

Create table code

CREATE TABLE Purchase (

PurchaseID varchar(10),

CustomerID VARCHAR(20),

DealersID varchar(10),

VehicleID varchar(10),

PurchaseDate Date,

PaymentMethod varchar(10),

Quantity INT,

TotalPrice int,

Primary key(PurchaseID),

Foreign key (CustomerID) references Customers(CustomerID),

Foreign key (DealersID) references Dealers(DealersID),

Foreign key (VehicleID) references Vehicle(VehicleID)

);

Insert code

INSERT INTO Purchase VALUES

('P-1', 'C-1', 'D-1', 'V-1', '2020-02-11', 'cash', 1, 4300000),

('P-2', 'C-2', 'D-2', 'V-2', '2020-11-05', 'credit cards', 1, 6600000),

('P-3', 'C-3', 'D-3', 'V-3', '2021-03-07', 'debit card', 2, 8800000),

('P-4', 'C-4', 'D-4', 'V-4', '2022-02-11', 'mobile payment', 1, 9100000),

('P-5', 'C-5', 'D-5', 'V-5', '2021-05-12', 'cash', 2, 16000000),

('P-6', 'C-6', 'D-4', 'V-6', '2021-02-11', 'credit cards', 1, 8300000),

('P-7', 'C-7', 'D-3', 'V-7', '2023-03-12', 'debit card', 1, 4500000),

('P-8', 'C-8', 'D-2', 'V-8', '2021-05-01', 'mobile payment', 2, 13800000),

('P-9', 'C-9', 'D-1', 'V-9', '2020-10-02', 'cash', 1, 4800000),

20
('P-10', 'C-10', 'D-5', 'V-10', '2020-02-25', 'credit cards', 1, 3700000),

('P-11', 'C-11', 'D-1', 'V-11', '2021-05-07', 'debit card', 2, 19000000),

('P-12', 'C-12', 'D-2', 'V-12', '2021-03-07', 'cash', 1, 8800000),

('P-13', 'C-13', 'D-3', 'V-13', '2020-12-11', 'mobile payment', 1, 9700000),

('P-14', 'C-14', 'D-4', 'V-14', '2021-03-07', 'debit card', 1, 5300000),

('P-15', 'C-15', 'D-4', 'V-15', '2020-05-01', 'cash', 2, 17800000),

('P-16', 'C-16', 'D-5', 'V-16', '2022-10-02', 'mobile payment', 1, 8700000),

('P-17', 'C-17', 'D-4', 'V-17', '2022-03-12', 'credit cards', 1, 4200000),

('P-18', 'C-18', 'D-1', 'V-18', '2021-03-07', 'debit card', 2, 6400000),

('P-19', 'C-11', 'D-2', 'V-19', '2021-12-11', 'mobile payment', 1, 8400000),

('P-20', 'C-10', 'D-2', 'V-20', '2020-02-11', 'cash', 1, 7400000),

('P-21', 'C-2', 'D-3', 'V-21', '2020-05-01', 'debit card', 2, 14800000),

('P-22', 'C-7', 'D-4', 'V-22', '2022-02-25', 'credit cards', 1, 4600000),

('P-23', 'C-3', 'D-5', 'V-23', '2022-05-07', 'cash', 1, 4200000),

('P-24', 'C-4', 'D-5', 'V-24', '2021-02-11', 'debit card', 2, 7400000),

('P-25', 'C-5', 'D-1', 'V-25', '2020-02-25', 'mobile payment', 1, 10000000),

('P-26', 'C-6', 'D-4', 'V-26', '2021-02-25', 'cash', 1, 7400000),

('P-27', 'C-17', 'D-3', 'V-27', '2021-02-25', 'credit card', 1, 7500000),

('P-28', 'C-18', 'D-5', 'V-28', '2020-02-25', 'mobile payment', 2, 9600000),

('P-29', 'C-9', 'D-4', 'V-29', '2021-02-25', 'debit card', 1, 9100000),

('P-30', 'C-13', 'D-3', 'V-30', '2022-02-25', 'cash', 2, 20000000);

21
ManufacturedBrand Table Data

Create table code

CREATE TABLE ManufacturedBrand

ManufacturedBrandID varchar(10) primary key,

Manufacture_ID varchar(10) ,

BrandID varchar(10) ,

SuppilerID varchar(10) ,

SupplyDate Date

FOREIGN KEY (Manufacture_ID) references


company_owned_manufacturing_plants(Manufacture_ID),

FOREIGN KEY (BrandID) references Brands(BrandID),

FOREIGN KEY (SuppilerID) references Suppliers(SuppilerID)

);

Insert code
INSERT INTO Manufactured_Brand (ManufacturedBrandID, Manufacture_ID, BrandID,
SuppilerID, SupplyDate) VALUES
('MB1', '1GN', 'B-1', 'S-1', '2020-01-01'),
('MB2', 'SVS', 'B-6', 'S-3', '2022-02-15'),
('MB3', 'JHM', 'B-4', 'S-7', '2020-03-10'),
('MB4', '1GN', 'B-3', 'S-4', '2021-04-05'),
('MB5', 'SVS', 'B-5', 'S-7', '2022-05-20'),
('MB6', 'JHM', 'B-1', 'S-3', '2020-06-15'),
('MB7', 'WBA', 'B-2', 'S-6', '2020-07-10'),
('MB8', 'JHM', 'B-3', 'S-2', '2021-08-25'),
('MB9', 'SVS', 'B-5', 'S-1', '2022-09-30'),
('MB10', 'WBA', 'B-2', 'S-4', '2023-10-15');

22
2.4 Customer Requirement

1. Show sales trends for various brands over the past 3 years, by year, month, week. Then
break these data out by gender of the buyer and then by income range.

2. Suppose that it is found that transmissions made by supplier Getrag between two given
dates are defective. Find the VIN of each car containing such a transmission and the
customer to which it was sold. If your design allows, suppose the defective
transmissions all come from only one of Getrag’s plants.

3. Find the top 2 brands by dollar-amount sold in the past year.

4. Find the top 2 brands by unit sales in the past year.

5. In what month(s) do convertibles sell best?

6. Find those dealers who keep a vehicle in inventory for the longest average time.

23
2.5 Query Planning with Algebra

Algebra 1: π sales trends (𝜎 purchaseDate = 2020 and purchaseDate = 2021 and purchaseDate = 2022
and count(gender)=maximum (Customers ⨝ Purchase ⨝ Vehicle));

Algebra 2:
Q1=σsuppilerName=′Getrag′∧SupplyDate between ′2020−1−1′ and ′2023−1−1′(Suppliers ⨝ Manufactured_brand)

Q2=Vehicle ⨝ purchase

Q3=Vehicle ⨝ Model_Option ⨝ Options

Temp=Q1 ⨝Q1.VehicleLiscense=Q3.VehicleLiscense Q3

Result=Temp ⨝ Q2

Final=πQ2.CustomerName, Q1.SupplyDate,Q1.VehicleLiscense,min(Q3.Transmission)(Result)
Algebra 3: π vin of each car (𝜎 supplier-name = “Getrag” (Vehicle ⨝ Supplier ⨝ ManufacturedBrand)):

Algebra 4: . π top2Brands (𝜎 year = 2022 and dollar-amount sold = maximum (Brands


⨝ Vehicle ⨝ Purchase));

Algebra 5: π months (𝜎 convertibles = 1 and year = 2020 and year = 2021 and year = 2022(Purchase X
Vehicle ⨝ Model-option ⨝ Options));

Algebra 6: π dealers (𝜎 average date = longest (dealers ⨝ dealerpurchase));

2.6 Query Execution with MySQL

24
Query 1
Select BrandName,year(PurchaseDate),month(PurchaseDate),week(PurchaseDate),Gender,Income

from Customers

natural join purchase

join vehicle on

purchase.VehicleID = vehicle.VehicleID

join Brands on vehicle.BrandID = Brands.BrandID WHERE year(PurchaseDate) in (2022,2021,2020)

order by Income DESC;

Outcome

25
Query 2
Input
SELECT

Q2.CustomerName, Q1.SupplyDate, Q1.VehicleLiscense, min( Q3.Transmission) AS TransmissionType

FROM

( SELECT SupplyDate, VehicleLiscense

FROM Suppliers AS SP

JOIN Manufactured_brand AS MB ON SP.SuppilerID = MB.SuppilerID

NATURAL JOIN brands

NATURAL JOIN vehicle

WHERE suppilerName = 'Getrag' and SupplyDate between ‘2020-1-1' and '2023-1-1'

) AS Q1

INNER JOIN

( SELECT V.VehicleLiscense, O.Transmission

FROM Vehicle V

JOIN Model_Option MO ON V.ModelID = MO.ModelID

JOIN Options O ON MO.OptionID = O.OptionID

) AS Q3 ON Q1. VehicleLiscense = Q3. VehicleLiscense

LEFT JOIN

( SELECT VehicleLiscense, CustomerName

FROM Vehicle

JOIN purchase ON vehicle.vehicleID = purchase.vehicleID

NATURAL JOIN customers

) AS Q2 ON Q1.VehicleLiscense = Q2.VehicleLiscense

GROUP BY Q2.CustomerName, Q1.SupplyDate, Q1.VehicleLiscense;

Outcome

26
Query 3
Input
Select BrandName, TotalPurchase
From
(
Select BrandName, sum(TotalPrice) as TotalPurchase
From Brands, Vehicle, Purchase

Where Year(PurchaseDate) = 2022


And Vehicle.VehicleID = Purchase.VehicleID
And Brands.BrandID = Vehicle.BrandID

Group by BrandName
Order By TotalPurchase desc
Limit 2
)
As TopBrands;

Outcome

27
Query 4
Input
Select BrandName, TotalUnitSales
From
(
Select BrandName, Sum(Quantity) as TotalUnitSales
From Brands, Vehicle, Purchase

Where Year (PurchaseDate) = 2022


And Vehicle.VehicleID = Purchase.VehicleID
And Brands.BrandID = Vehicle.BrandID

Group by BrandName
Order by TotalUnitSales desc
Limit 2
)
As TopBrands ;

Outcome

28
Query 5
Input
SELECT

MONTH(P.PurchaseDate) AS Month,

COUNT(MONTH(P.PurchaseDate)) AS ConvertibleCount

FROM

Purchase AS P

JOIN

Vehicle AS V ON P.VehicleID = V.VehicleID

JOIN

Model_Option AS MO ON MO.ModelID = V.ModelID

JOIN

Options AS O ON O.OptionID = MO.OptionID

WHERE

O.Convertible = 1

GROUP BY

MONTH(P.PurchaseDate)

limit 1;

Outcome

29
Query 6
Input
SELECT Dealername, ROUND(AVG(sumdate)) AS Average_Days

FROM (

SELECT Dealername, SUM(supplyTimeinDays) AS sumdate

FROM dealers

JOIN dealerpurchase ON dealers.DealersID = dealerpurchase.DealersID

GROUP BY dealers.DealersID, Dealername

) AS Result

GROUP BY Dealername

ORDER BY average_Days DESC LIMIT 1;

30
Chapter-3
Conclusion
This project aims to create a relational database system for an Automobile Company,
and to have functionality to address and solve specific requirements and problems for
specific situations. From the entities and queries to how the ERD will be constructed, the
aim, vision and planning was a crucial part of the project.

Looking at the finished project, it can be safe to say that the aims and requirements
have come to fruition. After the planning of the ERD and the creation of entities, the
requested queries and requirements were able to be executed with minimal adjustment to
the database, showing that the system is flexible and made to accommodate different
scenarios.

The process of the coding and development of the database itself was made with care
and caution. Each member did their assigned role, and their work was constantly under
review and feedback by fellow team members, creating a more usable, standardized result.
The work was also coordinated and efficient, making use of cloud-based word processing
software to record and document the tasks of each member. Whether in person or online,
discussions were common, proving the members’ enthusiasm to see a great finalized
product.

Arguably the most important part of a project after most of it has finished is the
documentation of the project itself. This was kept in mind during all stages of the project,
by use of the previously mentioned word software as well as the topic of documentation
being a common point of discussion in meetings. In this final document, care is given to
document every aspect of it and in a clear, concise way. No standard was dropped in the
writing of the data dictionary, query list, output preview, relational algebra and so on,
creating a report that helps not only people involved in the project, but also anyone that
might take an interest.

All in all, the project can be rounded up to a success. While we face minor issues in
the planning and design phase of the database, they were quickly dealt with and discussed
over. The finished project can fulfill the requirements and queries imposed upon it, and it is
our confident hope that it can also meet any future challenges it might face.

31

You might also like