0% found this document useful (0 votes)
11 views22 pages

Kamalpreet Kaur

Uploaded by

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

Kamalpreet Kaur

Uploaded by

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

CASE STUDY:

IDENTIFYING 986037

COMMON DEVICE Kamalpreet


kaur
REPAIRS AND
ASSOCIATED
COSTS
Table of Contents
Assignment (Part A):...................................................................................................................................2
1. Entities and Attributes........................................................................................................................2
2. Data Model.........................................................................................................................................2
3. Normalization to 3NF..........................................................................................................................2
4. Data Dictionary...................................................................................................................................2
Assignment (Part B):...................................................................................................................................5
SQL Scripts (A):........................................................................................................................................5
SQL Scripts (B):........................................................................................................................................6
Assignment (Part A):

1. Entities and Attributes


 Customer (c.CustomerID, c.Name, c.Address, c.PhoneNumber)

 Device (d.DeviceID, d.Type, d.Model, d.SerialNumber)

 Repair (r.RepairID, r.ReferenceNumber, r.Date, r.ProblemDescription, r.Cost,


r.EstimatedCompletionDate)

 Employee (e.EmployeeID, e.Name, e.DateOfJoining, e.HourlyWage, e.Role)

2. Data Model

3. Normalization to 3NF
The current model is already in 3NF because:

 There are no repeating groups of attributes.

 All non-key attributes are fully dependent on the primary key of the table they belong to.
 There are no transitive dependencies.

4. Data Dictionary
Table: Customer

Field Name Data Type Description (Constraints) Primary


Key
c.CustomerID INT Unique identifier for the customer (auto- YES
increment)

c.Name VARCHAR(255 Name of the customer


)

c.Address VARCHAR(255 Customer's address


)

c.PhoneNumbe VARCHAR(20) Customer's phone number


r

Table: Device

Field Name Data Type Description (Constraints) Primary


Key
d.DeviceID INT Unique identifier for the device (auto- YES
increment)

d.Type VARCHAR(50) Type of device (e.g., Smartphone, Laptop)

d.Model VARCHAR(255) Model of the device


d.SerialNumbe VARCHAR(50) Unique serial number of the device
r

Table: Repair

Field Name Data Type Description Primar Foreign


(Constraints) y Key Key
r.RepairID INT Unique identifier for YES
the repair (auto-
increment)

r.ReferenceNumber VARCHAR(50) Unique reference


number for the repair

r.Date DATE Date the repair was


brought in

r.ProblemDescription TEXT Description of the


problem

r.Cost DECIMAL(10,2) Total cost of the


repair (nullable)

r.EstimatedCompletionDat DATE Estimated date of


e repair completion
(nullable)

r.CustomerID INT Foreign key c.CustomerID


referencing Customer
table

r.DeviceID INT Foreign key d.DeviceID


referencing Device
table

r.EmployeeID INT Foreign key e.EmployeeID


referencing
Employyee table

Table: Employee

Field Name Data Type Description (Constraints) Primary


Key
e.EmployeeID INT Unique identifier for the employee (auto- YES
increment)

e.Name VARCHAR(255) Name of the employee


e.DateOfJoinin DATE Date the employee joined the company
g
e.HourlyWage DECIMAL(10,2 Employee's hourly wage
)

e.Role VARCHAR(50) Employee's role (e.g., Technician, Receptionist)


Assignment (Part B):
SQL Scripts (A):
File Name:

< Kamalpreet. 986037>_definition.SQL

Code:

-- Creating the database

create database Kamalpreet;

-- Using the database

use Kamalpreet;

-- Creating the Customer Table

CREATE TABLE Customer (

c_CustomerID INT PRIMARY KEY AUTO_INCREMENT,

c_Name VARCHAR(255) NOT NULL,

c_Address VARCHAR(255) NOT NULL,

c_PhoneNumber VARCHAR(20) NOT NULL

);

-- Creating the Device Table

CREATE TABLE Device (

d_DeviceID INT PRIMARY KEY AUTO_INCREMENT,

d_Type VARCHAR(50) NOT NULL,

d_Model VARCHAR(255) NOT NULL,

d_SerialNumber VARCHAR(50) NOT NULL

);
-- Creating the Repair Table

CREATE TABLE Repair (

r_RepairID INT PRIMARY KEY AUTO_INCREMENT,

r_ReferenceNumber VARCHAR(50) NOT NULL,

r_Date DATE NOT NULL,

r_ProblemDescription TEXT NOT NULL,

r_Cost DECIMAL(10,2) DEFAULT NULL,

r_EstimatedCompletionDate DATE DEFAULT NULL,

r_CustomerID INT NOT NULL,

r_DeviceID INT NOT NULL,

r_EmployeeID INT, -- Add this column to store the employee ID

FOREIGN KEY (r_CustomerID) REFERENCES Customer(c_CustomerID),

FOREIGN KEY (r_DeviceID) REFERENCES Device(d_DeviceID),

FOREIGN KEY (r_EmployeeID) REFERENCES Employee(e_EmployeeID)

);

-- Creating the Employee Table

CREATE TABLE Employee (

e_EmployeeID INT PRIMARY KEY AUTO_INCREMENT,

e_Name VARCHAR(255) NOT NULL,

e_DateOfJoining DATE NOT NULL,

e_HourlyWage DECIMAL(10,2) NOT NULL,

e_Role VARCHAR(50) NOT NULL

);

SQL Scripts (B):

File Name:

< Kamalpreet. 986037>_Tasks.SQL


Code:

-- For the Addition of 10 devices (replace model names with your choices)

INSERT INTO Device (d_Type, d_Model, d_SerialNumber) VALUES

('Smartphone', 'Pixel 6 Pro', '123ABC456DEF'),

('Laptop', 'MacBook Air M2', '789GHI012JKL'),

('Tablet', 'Galaxy Tab S8 Ultra', '345MNO678PQR'),

('MP3 Player', 'Walkman NW-A510', '90XYZ123EFG'),

('Smartphone', 'iPhone 14 Pro Max', '567TUV890WXY'),

('Laptop', 'ROG Zephyrus G14', '234DEFGHIJ'),

('Tablet', 'Surface Go 3', '890GHIJKLMO'),

('MP3 Player', 'SanDisk Clip Sport Plus', '123PQR456STU'),

('Smartphone', 'Galaxy S23 Ultra', '456JKL789MNO'),


('Laptop', 'IdeaPad Gaming 3', '012QWE345RT');

-- For the addition of customer details


INSERT INTO Customer (c_Name, c_Address, c_PhoneNumber) VALUES
('Bob', '1123 Central St, Melbourne, Australia', '023-91176-1132'),
('John Smith', '123 Main St, Melbourne, Australia', '03-9876-5432'),
('Kamalpreet Kaur (Student 986037)', 'Anu Street, Sydney, Australia', '0412-345-678');

-- For the addition of customer details (replace details with your information)

INSERT INTO Customer (c_Name, c_Address, c_PhoneNumber) VALUES

('Your Name', 'Your Address', 'Your Phone Number'),

('John Smith', '123 Main St, Melbourne, Australia', '03-9876-5432'),

('Kamalpreet Kaur (Student 986037)', 'Anu Street, Sydney, Australia', '0412-345-678');


-- For the addition of employee details

INSERT INTO Employee (e_Name, e_DateOfJoining, e_HourlyWage, e_Role) VALUES

('John Technician', '2023-01-01', 35.00, 'Technician'),

('Jane Receptionist', '2022-06-15', 20.00, 'Receptionist'),

('Mike Manager', '2021-12-31', 50.00, 'Manager'),

('Sarah Technician', '2024-01-10', 32.00, 'Technician'),

('David Sales', '2023-07-15', 25.00, 'Sales'),

('Emily Intern', '2024-05-20', 15.00, 'Intern');


-- For the addition of repair entries for each customer

INSERT INTO Repair (r_ReferenceNumber, r_Date, r_ProblemDescription, r_CustomerID, r_DeviceID,


r_Cost, r_EstimatedCompletionDate, r_EmployeeID)

VALUES

('REP006', '2024-05-29', 'Battery replacement', 1, 1, 75.00, '2024-05-31', 1),

('REP007', '2024-06-10', 'Screen cracked', 1, 5, 120.00, '2024-06-14', 2),

('REP008', '2024-05-28', 'Water damage', 2, 3, 180.00, '2024-06-03', 3),

('REP009', '2024-05-30', 'Software issue', 2, 9, 60.00, '2024-06-01', 1),

('REP010', '2024-05-24', 'Button malfunction', 3, 2, 30.00, '2024-05-28', 2),

('REP011', '2024-05-27', 'Keyboard issue', 3, 7, 85.00, '2024-05-30', 3);


-- For the updation of the model of the 5th device

UPDATE Device

SET d_Model = 'Redmi 13C'

WHERE d_DeviceID = 5;
-- For the updation of phone number

UPDATE Customer

SET c_PhoneNumber = '0123456789'

WHERE c_CustomerID = 3;
-- For the addition of instructor details

INSERT INTO Customer (c_Name, c_Address, c_PhoneNumber) VALUES

('Sakhshi Kapoor', 'Wentworth Institute of Higher Education, Sydney, Australia', '(02) 8252-999');
-- For showing the repairs for the 2nd customer (Kamalpreet Kaur)

SELECT r.r_ReferenceNumber, r.r_Date, r.r_ProblemDescription

FROM Repair r

INNER JOIN Customer c ON r.r_CustomerID = c.c_CustomerID

WHERE c.c_Name = 'Kamalpreet Kaur (Student 986037)';

-- For listing the customer names for repairs involving "Battery Replacement"

SELECT c.c_Name

FROM Customer c

INNER JOIN Repair r ON r.r_CustomerID = c.c_CustomerID

WHERE r.r_ProblemDescription LIKE '%Battery replacement%';


-- For displaying the customer names and total repair count using JOIN

SELECT c.c_Name, COUNT(*) AS TotalRepairs

FROM Customer c

INNER JOIN Repair r ON r.r_CustomerID = c.c_CustomerID

GROUP BY c.c_Name;
-- For listing all devices repaired for you (assuming you're customer 1)

SELECT d.d_Type, d.d_Model, d.d_SerialNumber

FROM Device d

INNER JOIN Repair r ON d.d_DeviceID = r.r_DeviceID

WHERE r.r_CustomerID = 1;
SELECT e.e_Name

FROM Employee e

WHERE EXISTS (

SELECT 1

FROM Repair r

WHERE e.e_EmployeeID = r.r_EmployeeID

AND r.r_Cost >= 50


-- For retrieving customer names who never had a repair involving "Screen Replacement."

SELECT c.c_Name

FROM Customer c

LEFT JOIN Repair r ON c.c_CustomerID = r.r_CustomerID

WHERE r.r_ProblemDescription IS NULL OR r.r_ProblemDescription NOT LIKE '%Screen Replacement%';


-- For identifiying the most common device type based on repair frequency and lists customers who own
that type of device.

SELECT c.c_Name AS CustomerName, COUNT(*) AS TotalRepairs,

AVG(CASE WHEN d.d_Type = (

SELECT d.d_Type

FROM (

SELECT d.d_Type, COUNT(*) AS RepairCount

FROM Device d

JOIN Repair r ON d.d_DeviceID = r.r_DeviceID

GROUP BY d.d_Type

ORDER BY RepairCount DESC

LIMIT 1

) AS MostCommonDevice

) THEN r.r_Cost ELSE NULL END) AS AvgRepairCostForMostCommonDevice

FROM Customer c
JOIN Repair r ON c.c_CustomerID = r.r_CustomerID

JOIN Device d ON r.r_DeviceID = d.d_DeviceID

GROUP BY CustomerName;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy