You are on page 1of 41

Final Project Report

ITS 232

Pet Shop Database System


SEMESTER MARCH – AUGUST 2021
GROUP: JCS1434E

AINA SYAKINAH BINTI RAHIM


2020893112

AZREEN AZRINA BINTI AZMAN


2020839674

NUR ANITA NAZIRA BINTI FAIRUZ ANNAN


2020877614

SYAFIQAH MAISARAH BINTI HAZMAN


2020843038
FINAL PROJECT REPORT ITS 232

Table of Contents

1. Project Overview 3
1.1 Organization Background 3
1.2 Current System Descriptions 4
1.3 Project Objectives 8

2. Business Rules and Entity Relationship Diagram (ERD) 9


2.1 List of Business Rules 9
2.2 Complete ER Diagram 11
2.3 Data Dictionary 10
2.4 Complete Relational Schema 13

3. Database Declaration 14
3.1 Tables 14

4. SQL Statements 20
4.1 Simple SQL Queries 20
4.2 Retrieving Data from Multiple Tables 25
4.3 Scalar Functions and Arithmetic/ Column Functions and Grouping 30
4.4 Sub Queries / Maintaining Data 35

5. References 40

2|Page
FINAL PROJECT REPORT ITS 232

1. Project Overview
1.1 Organization Background

Pet Lovers Centre (PLC) is not only the largest online pet store in Malaysia, but also the
largest and only pet care retail chain in Southeast Asia. The Pet Lovers Centre group was
founded in 1973 and has its headquarters in Singapore. PLC continues to satisfy pet
owners and animals. This is due to the fact that shopping at Pet Lovers Centre is all about
value and continually improving deals. The Pet Lovers Centre provides customers with
the largest and most recent selection of products, along with prompt, friendly, and helpful
service. The store sells over 15000 products from hundreds of pet care brands, allowing
all pet owners to purchase all pet supplies. The Pet Lovers Centre, therefore, provides the
best shopping experience ever.

Figure 1: Pet Lovers Centre – Malaysia HQ in Shah Alam

Figure 2: Pet Lovers Center - Johor Branch

3|Page
FINAL PROJECT REPORT ITS 232

1.2 Current System Descriptions

Pet Lovers Centre (PLC) is a pet shop that sells over 15000 products across hundreds of pet care
brands. Every pet owner can buy all pet supplies to take care of their pets. To exceed customers'
expectations and provide exceptional service, the shop develops one database with the following
business operations:
Staff can serve many customers. Staff personal details such as staff ID, name, contact, address,
hired date will be recorded when recruiting new employees. Many employees can organize many
products. Customers can buy many products. Each product purchase will record the product ID,
name, price, category, manufactured date, and supplier ID. A staff member can sell many
products. Customers can make an order through a stall or online platform. When customers make
an order at the stall or online platform, customer personal details such as customer ID, name,
contact, address, order dat,e and pet ID will be recorded. All the products purchased by customers
viaonline platform will be delivered to the customers’ address. A supplier will supply many
products for the shop. Each supplier will record suppliers’ personal details such as supplier ID,
name, contact, company name, address and product ID. The specifics of the products will be
documented such as product ID, name, price, category, manufactured, date and supplier ID.
Many products will be stored in many storages.

4|Page
FINAL PROJECT REPORT ITS 232

1.2.1 SUPPLIER FLOWCHART

5|Page
FINAL PROJECT REPORT ITS 232

1.2.2 EMPLOYEE FLOWCHART

6|Page
FINAL PROJECT REPORT ITS 232

1.2.3 CUSTOMER FLOWCHART

7|Page
FINAL PROJECT REPORT ITS 232

1.3 Project Objectives

i) To ensure better quality products and always fresh for customers.

ii) To ensure fair prices for customers.

iii) To bring you the latest product, also ensuring you get what customer needs.

8|Page
FINAL PROJECT REPORT ITS 232

2. Business Rules and Entity Relationship Diagram (ERD)


2.1 List of Business Rules

1 M
STAFF CUSTOMER
SERVE

A staff can serve many customers.


Each customer is served by only one staff.
Relationship: 1 to Many

M N
CUSTOMER PRODUCT
GET

Customers can get many products.


Each product can be get by many customers.
Relationship: Many to Many

9|Page
FINAL PROJECT REPORT ITS 232

1 M
PRODUCT SUPPLIER
PROVIDE
D

A product can be provided by many suppliers.


Each supplier provided only one product.
Relationship: 1 to Many

1 M
CUSTOMER PET
GRAB

A customer can grab many pets.


Each pet is grabbed by only one customer.
Relationship: 1 to Many

10 | P a g e
FINAL PROJECT REPORT ITS 232

2.2 Complete ER Diagram

CUSTOMER ORDER PRODUCT


PK CustID get PK,FK1 CustID get PK ProductID
get
FK StaffID || |< PK,FK2 ProductID >| || ProductName
CustName ProductCategory
OrderType
CustAddress ProductPrice
OrderDate ProductManufacturedDate
>|
CustContact

grab provided
STAFF
PK StaffID

StaffName
StaffAddress
StaffContact
PET
StaffHiredDate
PK PetID SUPPLIER
FK CustID PK SupplierID
PetName
FK ProductID
PetGender
SupplierContact
PetDOB
SupplierCompany
PetType
SupplierAddress

No. of Tables = 6

11 | P a g e
FINAL PROJECT REPORT ITS 232

2.3 Data Dictionary

TABLE ATTRIBUTE NAME CONTENTS DATA FORMAT RANGE REQUIRED PK FK


NAME TYPE OR PREFERENCED
FK TABLE
STAFF StaffID Staff ID CHAR(4) 9999 0-9999 Y PK
StaffName Staff Name VARCHAR Xxxxxxxx Y
(30)
StafContact Staf Contact VARCHAR Xxxxxxxx Y
(15)
StaffAddress Staff Address VARCHAR Xxxxxxxx
(100)
StaffHiredDate Staff Hired Date DATE dd-mm-
yyyy
CUSTOME CustID Cust ID CHAR (4) 9999 0-9999 Y PK
R StaffID Staff ID CHAR (4) 9999 0-9999 FK STAFF
CustName Cust Name VARCHAR Xxxxxxxx Y
(30)
CustAddress Cust Address VARCHAR Xxxxxxxx
(80)
OrderDate Order Date DATE dd-mm-
yyyy
CustContact Cust Contact VARCHAR Xxxxxxxx Y
(15)
PET PetID Pet ID CHAR (4) 9999 Y PK
CustID Cust ID VARCHAR Xxxxxxxx FK CUSTOMER
(4)
PetName Pet Name VARCHAR Xxxxxxxx Y
(10)
PetGender Pet Gender VARCHAR Xxxxxxxx
(7)
PetDOB Pet DOB DATE dd-mm-
yyyy
PetType Pet Type VARCHAR Xxxxxxxx Y
(25)
PRODUCT ProductID Product ID CHAR (4) 9999 0-9999 Y PK

ProductName Product Name VARCHAR Xxxxxxxx Y


(25)
ProductCategory Product VARCHAR Xxxxxxxx Y
Category (10)

11 | P a g e
FINAL PROJECT REPORT ITS 232

ProductPrice Product Price DECIMAL 9,999.99 Y

ProductManufacturedDate Product DATE dd-mm-


Manufactured yyyy
Date
SUPPLIER SupplierID Supplier ID CHAR (4) 9999 0-9999 Y PK
ProductID Product ID CHAR (4) 9999 0-9999 FK PRODUCT
SupplierContact Supplier Contact VARCHAR Xxxxxxxx Y
(15)
SupplierCompany Supplier VARCHAR Xxxxxxxx Y
Company (30)
SupplierAddress Supplier VARCHAR Xxxxxxxx
Address (100)
ORDER CustID Cust ID CHAR (4) 9999 0-9999 PK1, CUSTOMER
FK1
ProductID Product ID CHAR (4) 9999 0-9999 PK2, PRODUCT
FK2
OrderType Order Type VARCHAR Xxxxxxxx Y
(15)

12 | P a g e
FINAL PROJECT REPORT ITS 232

2.4 Complete Relational Schema


STAFF (StaffID, StaffName, StaffContact, StaffAddress, StaffHiredDate )CUSTOMER

( CustID, StaffID*, CustName, CustAddress, OrderDate, CustContact)

PET (PetID, CustID*, PetName, PetGender, PetDOB, PetType)

PRODUCT (ProductID, ProductName, ProductCategory, ProductPrice,


ProductManufacturedDate )

SUPPLIER (SupplierID, ProductID*, SupplierContact, SupplierCompany, SupplierAddress)

ORDER (CustID*, ProductID*, OrderType)

13 | P a g e
FINAL PROJECT REPORT ITS 232

3. Database Declaration
3.1 Tables

1. Table: STAFF

CREATE TABLE STAFF (

StaffID CHAR(4) NOT NULL,

StaffName VARCHAR(30),

StaffContact VARCHAR(15),

StaffAddress VARCHAR(100),

StaffHiredDate DATE,

PRIMARY KEY (StaffID));

Sample of output :

14 | P a g e
FINAL PROJECT REPORT ITS 232

2. Table: CUSTOMER

CREATE TABLE CUSTOMER (

CustID CHAR(4) NOT NULL,

StaffID CHAR(4) NOT NULL,

CustName VARCHAR(30),

CustContact VARCHAR(15),

CustAddress VARCHAR(80),

OrderDate DATE,

PRIMARY KEY (CustID),

FOREIGN KEY (StaffID) REFERENCES STAFF(StaffID));

Sample of output :

15 | P a g e
FINAL PROJECT REPORT ITS 232

3. Table: PET

PetID CHAR(4) NOT NULL,

CustID VARCHAR(4),

PetName VARCHAR(10),

PetType VARCHAR(25),

PetGender VARCHAR(7),

PetDOB DATE,

PRIMARY KEY (PetID),

FOREIGN KEY (CustID) REFERENCES CUSTOMER (CustID));

Sample of output :

16 | P a g e
FINAL PROJECT REPORT ITS 232

4. Table: PRODUCT

CREATE TABLE PRODUCT (

ProductID CHAR(4) NOT NULL,

ProductName VARCHAR(25),

ProductCategory VARCHAR(10),

ProductManufacturedDate DATE,

ProductPrice DECIMAL(6,2),

PRIMARY KEY (ProductID));

Sample of output :

17 | P a g e
FINAL PROJECT REPORT ITS 232

5. Table: SUPPLIER

CREATE TABLE SUPPLIER (

SupplierID CHAR(4) NOT NULL,

ProductID CHAR(4) NOT NULL,

SupplierCompany VARCHAR(30),

SupplierContact VARCHAR(15),

SupplierAddress VARCHAR(100),

PRIMARY KEY (SupplierID),

FOREIGN KEY (ProductID) REFERENCES PRODUCT (ProductID));

Sample of output :

18 | P a g e
FINAL PROJECT REPORT ITS 232

6. Table: ORDER

CREATE TABLE ORDERS (

CustID CHAR(4) NOT NULL,

ProductID CHAR(4) NOT NULL,

OrderType VARCHAR(15),

PRIMARY KEY (CustID,ProductID),

FOREIGN KEY (CustID) REFERENCES CUSTOMER (CustID),

FOREIGN KEY (ProductID) REFERENCES PRODUCT (ProductID));

Sample of output :

19 | P a g e
FINAL PROJECT REPORT ITS 232

4. SQL Statements

4.1 Simple SQL Queries

Query 1:
List each staff ID, staff name, staff contact number and staff address where the staff are
hired after 2020. Sequence the list by staff hired date descendingly.

SELECT StaffID, StaffName, StaffContact, StaffAddress


FROM STAFF
WHERE StaffHireddate >= '2020/01/01'
ORDER BY StaffHireddate DESC;

20 | P a g e
FINAL PROJECT REPORT ITS 232

Query 2:
List product ID, product name, product category and product price where the product
price is greater than or equal to RM50. Sequence the list by product price ascendingly.

SELECT ProductID, ProductName, ProductCategory, ProductPrice


FROM PRODUCT
WHERE ProductPrice >= '50.00'
ORDER BY ProductPrice ASC;

21 | P a g e
FINAL PROJECT REPORT ITS 232

Query 3:
List customer ID and order type where product ID is greater than ‘Y010’ and order type
is purchase order. Sequence the list by customer ID ascendingly.

SELECT CustID, OrderType


FROM ORDERS
WHERE ProductID > 'Y010' AND
OrderType = 'Purchase Order'
ORDER BY CustID ASC;

22 | P a g e
FINAL PROJECT REPORT ITS 232

Query 4:
List supplier company, supplier contact number and supplier address where the supplier
ID is more than ‘X015’ or product ID is less than or equal to ‘Y005’. Order the list by
supplier ID descendingly.

SELECT SupplierCompany, SupplierContact, SupplierAddress


FROM SUPPLIER
WHERE SupplierID > 'X015' OR ProductID <= 'Y005'
ORDER BY SupplierID DESC;

23 | P a g e
FINAL PROJECT REPORT ITS 232

Query 5:
List the category of product available in the pet shop and order the list by product
category alphabetically.

SELECT DISTINCT ProductCategory


FROM PRODUCT
ORDER BY ProductCategory ASC;

24 | P a g e
FINAL PROJECT REPORT ITS 232

4.2 Retrieving Data from Multiple Tables

Query 1:
List staff ID and staff name for all customers. Sequence the list by staff ID.

SELECT S.StaffID, S.StaffName, C.CustID, C.CustName, C.CustAddress


FROM STAFF S, CUSTOMER C
WHERE S.StaffID = C.StaffID
ORDER BY S.StaffID ASC;

25 | P a g e
FINAL PROJECT REPORT ITS 232

Query 2:
Identify manufacture date of product category food. Display the supplier ID, supplier
company, supplier contact, product category and product manufactured date. List by
supplier ID.

SELECT L.SupplierID, L.SupplierCompany, L.SupplierContact, P. ProductCategory,


P.ProductManufacturedDate
FROM SUPPLIER L, PRODUCT P
WHERE P.ProductID = L.ProductID
AND P.ProductCategory = 'FOOD'
ORDER BY L.SupplierID ;

26 | P a g e
FINAL PROJECT REPORT ITS 232

Query 3:
Display supplier ID, supplier company, product name and product category. Order the
list by supplier ID in ascending order.

SELECT L.SupplierID, L.SupplierCompany, P.ProductName, P.ProductCategory


FROM SUPPLIER L, PRODUCT P
WHERE P.ProductID = L.ProductID
ORDER BY L.SupplierID ASC;

27 | P a g e
FINAL PROJECT REPORT ITS 232

` Query 4:
Identify the pet for all customers. Display customer ID, customer name, pet name, pet
type and pet date of birth.

SELECT C.CustID, C.CustName, T.PetName, T.PetType, T.PetDOB


FROM CUSTOMER C, PET T
WHERE C.CustID = T.CustID
ORDER BY C.CustID;

28 | P a g e
FINAL PROJECT REPORT ITS 232

Query 5:
Identify all orders made by customers that show customer ID, product category and
order type. Order by order type descending.

SELECT C.CustID, P.ProductCategory, O.OrderType


FROM CUSTOMER C, PRODUCT P, ORDERS o
WHERE C.CustID = O.CustID
AND P.ProductID = O.ProductID
ORDER BY O.OrderType DESC;

29 | P a g e
FINAL PROJECT REPORT ITS 232

4.3 Scalar Functions and Arithmetic/ Column Functions and Grouping

Query 1:
List the staff where the staff start working before 2022. Display the year and the month
of the hire date and staff id. Name the derived column YEAR and MONTH.

SELECT StaffID, YEAR(StaffHiredDate) AS YEAR, MONTH(StaffHiredDate) AS


MONTH
FROM STAFF
WHERE StaffHiredDate <'2022/01/01';

30 | P a g e
FINAL PROJECT REPORT ITS 232

Query 2:
The price of the product for product type medicine will decrease by RM20 for each. List
the product name, product id, product price and the decrese price for product. Use the
name LessProduct for the generated column.

SELECT ProductName, ProductID, ProductPrice, (ProductPrice - 20) AS LessProduct


FROM PRODUCT
WHERE ProductCategory = 'MEDICINE' ;

31 | P a g e
FINAL PROJECT REPORT ITS 232

Query 3:
Calculate the total product price for all medicine products. Display the product
category and total price.

SELECT ProductCategory, SUM(ProductPrice) AS Total_Price


FROM PRODUCT
WHERE ProductCategory = 'MEDICINE'
GROUP BY ProductCategory
ORDER BY (ProductCategory);

32 | P a g e
FINAL PROJECT REPORT ITS 232

Query 4:
Display the average for all products with an average below RM200. List the product
category and average.

SELECT ProductCategory, ROUND(AVG( ProductPrice),2) AS


AveragePrice FROM PRODUCT
GROUP BY ProductCategory
HAVING AVG(ProductPrice)<200
ORDER BY ProductCategory;

33 | P a g e
FINAL PROJECT REPORT ITS 232

Query 5:
For all pets, count the number of pets owned by a customer.

SELECT CustID, COUNT(*) AS TotalPet


FROM PET
GROUP BY CustID
ORDER BY CustID;

34 | P a g e
FINAL PROJECT REPORT ITS 232

4.4 Sub Queries / Maintaining Data

Query 1:
Find product name, category of product and the price of product that have
the lowest price.

SELECT ProductName, ProductCategory, ProductPrice


FROM PRODUCT
WHERE ProductPrice=(SELECT MIN(ProductPrice) FROM PRODUCT);

35 | P a g e
FINAL PROJECT REPORT ITS 232

Query 2:
List customer name and customer contact number who own female pets only.

SELECT CustName, CustContact


FROM CUSTOMER
WHERE CustID IN (SELECT CustID
FROM PET
WHERE PetGender= 'FEMALE' );

36 | P a g e
FINAL PROJECT REPORT ITS 232

Query 3:
List customer name, customer contact number and customer address where
the postcode is not ‘40150’ and order the list alphabetically.

SELECT CustName, CustContact, CustAddress


FROM CUSTOMER
WHERE CustAddress NOT IN (SELECT CUSTADDRESS FROM CUSTOMER
WHERE CustAddress LIKE '%40150%')
ORDER BY CustName ASC;

37 | P a g e
FINAL PROJECT REPORT ITS 232

Query 4:
From table Product, find those product who got the second-highest price.
Return all the fields of the product.

SELECT *
FROM PRODUCT
WHERE ProductPrice = (SELECT ProductPrice
FROM PRODUCT
WHERE ProductPrice = (SELECT MAX(ProductPrice)
FROM PRODUCT
WHERE ProductPrice < (SELECT MAX(ProductPrice)
FROM PRODUCT)));

38 | P a g e
FINAL PROJECT REPORT ITS 232

Query 5:
Display PetID, CustID, PetName, PetType, and PetGenderwith the modified title
“Pet_Category” for the PetGender whose is ‘MALE’ and ‘FEMALE’. List all the
fields with the PetName in ascending order.

SELECT P.PetID, P.PetName, P.PetType, P.PetGender, C.CustID,


P.PetType AS Pet_Category
FROM PET P, CUSTOMER C
WHERE P.CustID IN (SELECT CustID
FROM PET
WHERE PetGender IN ('MALE','FEMALE'))
AND P.CustID = C. CustID
ORDER BY PetID ASC;

39 | P a g e
FINAL PROJECT REPORT ITS 232

5. References

1) Database System Concepts - 6th Edition.” Database System Concepts - 6th Edition, db-
book.com, 2016, https://db-book.com/db6/index.html.
2) Database System Concepts - 7th Edition.” Database System Concepts - 7th Edition, db-
book.com, 0 0 2017, https://db-book.com/.
3) ICT200.pdf. (2022). ebook - ICT200.pdf. Google Docs.
https://drive.google.com/file/d/1VRkIN1mCyhLvlfv6RCg1Ly9n_xQqset-/view
4) Notes and video lecture by Puan Suhanah Rosnan
5) Sql.Js Demo: Online SQL Interpreter.” Sql.Js Demo: Online SQL Interpreter, db-
book.com, 2022, https://db-book.com/university-lab-dir/sqljs.html.

40 | P a g e

You might also like