You are on page 1of 5

Case Study for Lecture A

“Start riding” is a chain of bike repair shops in Sydney. Because of the prevailing COVID 19
pandemic and increasing competition, the owners want to track the repair jobs for bikes they
repair, the items used for each repair job, the labor costs for each repair job, the mechanic
performing each repair job, and the total cost of each repair job.
The process is as follows:
When customers bring their bikes in to be repaired, they need to pay a deposit on the repair
job and are given a date to return and pick up their bikes after the mechanic evaluates the
repair job. Mechanic then perform the repairs on the customers’ bikes, details the labor costs
and the items used for each repair job.
When customers return on the date advised, they must pay the total cost of the repair job
less the deposit, collect a receipt for their payment, and pick up the repaired bikes using this
payment receipt.
Group Tasks
Task 1 ER Diagram 5 marks

 Identify the entities and indicate minimum/maximum. Resolve Many to many


relationships.
 Use UPPERCASE to name your entities and use Capitalisation (of first letter) to name
attributes of entities. Underline all primary key attributes and mention all the foreign key
attributes. Specify relationship verb.
 State your assumptions clearly.
 Create an ER diagram using crow’s foot notation in any tool of your choice. Hand drawn
diagrams will not be accepted.

Task 2 Normalization 5 marks

 List all the dependencies in a dependency diagram including partial and transitive.
 Show the determinants and select primary key, foreign key.
 Starting with unnormalized data, convert all the tables to 1 NF. Clearly outline the
rules for a table to be in 1 NF and provide justification.
 Identify partial dependency if any and resolve it.
 Identify transitive dependency if any and resolve it.
 Make sure the tables are in BCNF. Explain the rule with tables as example.
 Identify multivalued dependency if any and resolve it.
 At each stage list the rules and provide explanation of why the tables are in 2, 3 or 4
NF.

Task 3 10 marks
1. Write table creation scripts for all the entities identified in ERD above and insert a few
records in each table. 5 marks
2. Write the below queries: 5 marks
a. Listing of jobs on hand, mechanics working on them and items required for the job
arranged in descending order of completion date
b. List of customers who have paid more than $ 200 on the total job and a deposit of over $
50
c. A summary of all jobs that require more than 2 items to fix.
d. Names of mechanics who are working on more than 2 jobs at the same time.
e. Create a view which shows a list of repeat customers (those who have availed services
more than once). This view should display the name of mechanic, items used and total cost
for each of the jobs for these customers.

Answer: -

TASK-1

ENTITIES Customer Mechanic Job Item Booking


Customer_id Mechanic_name Job_id Item_id Invoice_id
Customer_name Mechanic_id Mechanic_id Item_name Customer_id_
_FK FK
Customer_add Job_id_Fk Item_id_FK Item_type Total_amount
Attributes
Invoice_id_FK Labour cost Item_cost Pickup_date
Deposit_Amt Booked_date
Customer_cellno

Before Normalization:
Customer_id integer
Customer_name varchar (20)
Customer_add varchar (200)
Invoice_id_FK integer
Deposit_Amt currency
Customer_cellno integer
Mechanic_id integer
Job_id_FK
Mechanic_name
Labour cost currency
Job_id integer
Item_id_FK integer
Item_id integer
Item_name varchar (20)
Item_type varchar (20)
Item_cost currency
Invoice_id integer
Customer_id_FK
Total_amount currency currency
Adv_paid currency
Pickup_date date
Booked_Date date
TASK-2

Task-3
Create Table script:
CREATE TABLE CUSTOMER(
Customer_id INT PRIMARY KEY NOT NULL,
Customer_name VARCHAR(20) NULL,
Customer_add VARCHAR(200) NULL,
Invoice_id_FK INT FOREIGN KEY REFERENCES BOOKING(Invoice_id)
Customer_cellno INT NOT NULL,
Deposit_Amt money NULL,
);

GO

CREATE TABLE BOOKING(


ProductID int PRIMARY KEY NOT NULL,
Customer_id_FK INT FOREIGN KEY REFERENCES CUSTOMER(Invoice_id)
Total_amount money NULL,
Adv_paid money NULL,
Pickup_date DATETIME2 NOT NULL
Booked_date DATETIME2 NOT NULL
);
GO

CREATE TABLE MECHANIC(


Mechani_name VARCHAR(20) NULL,
Mechanic_id INT PRIMARY KEY NOT NULL,
Job_id_FK INT FOREIGN KEY REFERENCES JOB(Job_id)
Labour cost money NULL,
Invoice_id_FK INT FOREIGN KEY REFERENCES BOOKING(Invoice_id)
);
GO

CREATE JOB(
Job_id INT PRIMARY KEY NOT NULL,
Mechanic_id_FK INT FOREIGN KEY REFERENCES MECHANIC(Mechanic_id)
Labour cost money NULL,
Item_id_FK INT FOREIGN KEY REFERENCES ITEM(Item_id)
);
GO

CREATE ITEM(
Item_id INT PRIMARY KEY NOT NULL,
Item_name VARCHAR(20) NULL,
Item_type VARCHAR(20) NULL,
Labour cost money NULL,
);
GO
=========================
Insert data

INSERT CUSTOMER (Customer_id, Customer_name, Customer_add, Invoice_id_FK,


Deposit_Amt, Customer_cellno)
VALUES (1, 'Chris', '14/2 rose villa apt, LA ', 111, 50, 4555544)
GO

INSERT BOOKING (Invoice_id, Customer_id_FK, Total_amount, Adv_paid,


Pickup_date,Booked_Date)
VALUES (111, 1, 250, 50 , '2013-10-11', '2013-10-10')
GO

INSERT MECHANIC(Mechanic_name, Mechanic_id, Job_id_FK, Labour cost,


Invoice_id_FK)
VALUES (Miller,11, 1, 25, 111)
GO

INSERT JOB(Job_id, Mechanic_id_FK, Item_id_FK)


VALUES (1, 11, , 121)
GO

INSERT ITEM(Item_id, Item_name, Item_type, Item_cost)


VALUES (100, 'plug','gear', 10)
GO

Add one column jobcompletedate in Job table

a)Select Jobs_id as Jobs on hand, Mechanic_id , items


FROM JOB
INNER JOIN MECHANIC
ON JOB.Job_id = Mechanic_id;
select Count(Item_id) as items
from ITEM
ORDER BY jobcompletedate;

b)SELECT e1.customer_name
FROM customer e1,e2.Booking
WHERE Deposit_Amt >= 200 and Totak_amount>200

c)select Job_id, Mechanic_id_FK, Item_id_FK from Job,Item group by


item_name having count(*)>2
d)select mechanic_name from Mechanic ,job group by job_id having
count(*)>2

e)create view [Repeat customers] As select mechanic_name, items_name,


total_amount from Mechanics ,Item , Booking , customer group by
customer_id having count(*)=1

You might also like