Arpan Karki L2C2
Arpan Karki L2C2
CC5051NT Databases
Year: 2023-24
Semester: 3rd Semester
I confirm that I understand my coursework needs to be submitted online via Google Classroom under the
relevant module page before the deadline in order for my assignment to be accepted and marked. I am
fully aware that late submissions will be treated as non-submission and a marks of zero will be awarded.
Table of Contents
1. Introduction ............................................................................................................... 1
3. Normalization .......................................................................................................... 11
Creating tables........................................................................................................... 17
Informational Queries................................................................................................. 38
Transactional query ................................................................................................... 43
References .................................................................................................................... 52
List of Figures
Figure 1 : Initial ERD ..................................................................................................... 10
Figure 2 : Final ERD ...................................................................................................... 16
Figure 3 : User creation ................................................................................................. 17
Figure 4 : Creation table for Customer .......................................................................... 18
Figure 5 : Customer table description ............................................................................ 18
Figure 6 : Creating table for Customer Category ........................................................... 19
Figure 7 : Customer Category table description ............................................................ 19
Figure 8 : Creating table for Product Category .............................................................. 20
Figure 9 : Product category table description ................................................................ 20
Figure 10 : Creating table for Vendor. ............................................................................ 21
Figure 11 : Vendor table description .............................................................................. 21
Figure 12 : Creating table for Invoice ............................................................................ 22
Figure 13 : Invoice table description .............................................................................. 22
Figure 14 : Creating table for Payment .......................................................................... 23
Figure 15 : Payment table description ........................................................................... 23
Figure 16 : Create table for product ............................................................................... 24
Figure 17 : Product table description ............................................................................. 25
Figure 18 : Creating table for Orders ............................................................................. 26
Figure 19 : Order table description ............................................................................... 26
Figure 20 : Creating table for Order Details ................................................................... 27
Figure 21 : Order details description ............................................................................. 27
Figure 22 : Inserting data into Customer category ......................................................... 28
Figure 23 : Inserting data into Customer ....................................................................... 29
Figure 24 : Inserting data into Product Category table .................................................. 30
Figure 25 : Inserting data into vendor table ................................................................... 31
Figure 26 : Inserting data into product table .................................................................. 33
Figure 27 : Inserting data into Payment table ................................................................ 34
Figure 28 : Inserting data into Invoice table ................................................................... 35
Figure 29 : Inserting data into Order table ..................................................................... 36
Figure 30 : Inserting data into Order_Details table ........................................................ 37
Figure 31 : Informational query 1 ................................................................................... 38
Figure 32 : Informational query 2 ................................................................................... 39
Figure 33 : Informational query 3 .................................................................................. 40
Figure 34 : Informational query 4 ................................................................................... 41
Figure 35 : Informational query 5 ................................................................................... 42
Figure 36 : Transactional query 1 .................................................................................. 43
Figure 37 : Transactional query 2 .................................................................................. 44
Figure 38 : Transactional query 3 .................................................................................. 45
Figure 39 : Transactional query 4 .................................................................................. 46
Figure 40 : Transactional query 5 ................................................................................. 46
Figure 41 : Command to create dump file ..................................................................... 47
Figure 42 : Exporting database to a dump file ............................................................... 48
Figure 43 : Proof of dump file creation .......................................................................... 49
List of Tables
Table 1 : Product attributes and their description ............................................................. 6
Table 2 : Customer attributes and their description ......................................................... 6
Table 3 : Order attributes with their description ............................................................... 7
Table 4 : Vendor attributes with their description ............................................................. 8
CC5051NT Databases
1. Introduction
Introduction of the business
Gadget Emporium, the store for everything electronic. An incredible online shop
where gadgets are such treasures. Our “tech-loving creator”, namely Mr. John,
envisioned this place so that everyone would be able to get “cool gadgets”.
Therefore, what is so significant about Gadget Emporium? It is like a giant online
store full of fantastic things. We have everything in technology; we’ve got
smartphones, laptops for gaming, camera equipment, and many other accessories
designed to make it easy and enjoyable. Now, imagine this: perhaps you discover
your dream gadgets, such as a stylish phone or an entertaining console. You can
purchase it by pushing a button just as easily as ordering a pizza via a website
though much more thrilling. And guess what? Gadget Emporium offers the fastest
delivery of new gadgets for you.
But here's the cool part: Gadget Emporium is not just a shop. A congenial gathering
point where businesses and technology enthusiasts get together. We have the
coolest stuff, even if you are one of those people who cannot live without new
gadgets and a company striving for the cutting edge in tech tools. It’s Mr. John’s
mission to ensure that your tech adventure is easy and enjoyable. He has a dream
that Gadget Emporium should not only be an ordinary place but one where you
find, experience, and probably even become amorous about marvelous items.
Think of it like a place where every techie dream is realized, and you are the main
character of the gadget epic.
➢ Make Gadget Emporium a fun place for all from gadget fans to businesses.
➢ Let people easily explore and find cool gadgets.
➢ Create a website that makes buying gadgets super easy.
➢ Offer businesses the latest tech tools with special deals for big orders.
➢ Be clear about product availability and let customers track their orders.
Arpan Karki 1
CC5051NT Databases
➢ Build a friendly place where tech fans and businesses connect and share.
Arpan Karki 2
CC5051NT Databases
xiv. Establish clear and fair return and refund policies to provide customers with
confidence and assurance in their purchases.
Business Rules
Business rules are essentially guidelines that dictate whether an individual can
execute a particular action that is relevant to the operation of the business. These
rules also outline the criteria and conditions necessary for making decisions. These
rules can be thought of as "standard operating procedures". Some of these
procedures might be complex, like reporting company financials to shareholders.
Others might be straightforward, such as a policy that stipulates all customer
applications must be completed in writing Business rules are generally designed
to provide employees with specific decision-making conditions, criteria, and
exceptions. Understanding these rules can help gain a better understanding of
different internal processes and identify reasons why business efforts sometimes
fail. (Jones, 2023)
Arpan Karki 3
CC5051NT Databases
Arpan Karki 4
CC5051NT Databases
2. Initial ERD
Identification of entities and attributes
An entity is a distinct real-world thing, such as a person, a place, or a concept, that
can be uniquely identified. It's an object that stands out from the crowd. The
properties of the object that defines the nature of object is known as Attribute.
(Chen, 2023)
The following are four identified entities Product, Customer, Order, and Vendor
each with associated attributes described as follows:
Arpan Karki 5
CC5051NT Databases
Product
Attributes Description
Customer
Attributes Description
Arpan Karki 6
CC5051NT Databases
Order
Attributes Description
Arpan Karki 7
CC5051NT Databases
Vendor
Attributes Description
Arpan Karki 8
CC5051NT Databases
Customer Customer_ID _ _ _
Initial ERD
The Initial ERD has four main entities: Customers (people who buy), Products
(things for sale), Orders (what customers buy), and Vendors (companies selling
products).
Customers: People buying things from the Gadget Emporium Online Store. In a
many-to-many way, customers and orders are connected. Every customer can
make different orders and each one of them can be linked with many customers.
Products: Items available for purchase on the Gadget Emporium Online Store.
Products and orders share a many-to-many relationship. A product can be part of
multiple orders, and each order may contain multiple products.
Arpan Karki 9
CC5051NT Databases
Arpan Karki 10
CC5051NT Databases
3. Normalization
Normalization is the process to eliminate data redundancy and enhance data
integrity in the table. Normalization also helps to organize the data in the database.
It is a multi-step process that sets the data into tabular form and removes the
duplicated data from the relational tables. (Ravikiran, 2023)
Unnormalized Form
The Unnormalized Form (UNF) represents the most basic database model
characterized by data redundancy and a lack of normalization efficiency. In this
normalization stage, the goal is to identify repeating groups and designate a
primary key for the purpose of improving data organization and eliminating
redundancies.
Assumptions:
An order can be made by many customers and each customer has an orders.
Customer can place one order for several products and correspondingly vendor
may supply many items at the same time.
Illustrating repeating data and repeating groups:
Customer (Customer_ID, Customer_Name, Customer_Address,
Customer_Contact, Customer_Category, Discount_Rate, { Order_ID,
Order_Name, Order_Quantity, Order_Date, Order_Amount, Payment_ID,
Payment_Type, Payment_Date, Amount,
Discount_Amount,Invoice_ID,Invoice_Date, Invoice_Amount { Product_ID,
Product_Name,Product_Desc,Product_Catagory,Product_Price,Stock_Quantity,
Stock_Level, Vendor_ID, Vendor_Name, Vendor_Contact,Vendor_Address }})
Arpan Karki 11
CC5051NT Databases
Distinguishing between groups that repeat and those that do not repeat.
Customer(Customer_ID,Customer_Name,Customer_Address,
Customer_Contact, Customer_Category,Customer_Cat_ID, Customer_Cat_Type,
Discount_Rate)
Order(Order_ID,Order_Name,Order_Quantity,Order_Date,
Order_Amount,Payment_ID,Payment_Type,Payment_Date,Amount,
Discount_Amount, Invoice_Amount, Customer_ID* )
Product(Product_ID,Product_Name,Product_Desc,Product_Cat_Type,
Product_Cat_ID,Inventory_ID,Product_Price,Stock_Level,Vendor_ID,
Vendor_Name, Vendor_Contact, Vendor_Address, Order_ID*)
Order_1(Order_ID,Order_Name,Order_Quantity,Order_Date,
Order_Amount,Payment_ID,Payment_Type,Payment_Date,Amount,
Discount_Amount, Invoice_Amount, Customer_ID* )
Product_1(Product_ID,Product_Name,Product_Desc,Product_Cat_Type,
Product_Cat_ID,Inventory_ID,Product_Price,Stock_Level,Vendor_ID,
Vendor_Name, Vendor_Contact, Vendor_Address, Order_ID*)
Arpan Karki 12
CC5051NT Databases
Because the product has a composite primary key, we assess whether there's any
partial reliance on specific components.
Product_ID, Order_ID →
Product_ID → Product_Name,Product_Desc,Product_Category,Stock_Quantity,
Stock_Level, Vendor_ID, Vendor_Name, Vendor_Contact, Vendor_Address)
OrderID → X
Product(Product_ID,Product_Name,Product_Desc,Product_Price,
Product_Cat_ID, Product_Cat_Type, Stock_Quantity, Stock_level, Vendor_ID,
Vendor_Name, Vendor_Address, Vendor_Contact)
Order(Order_ID,Order_Name,Order_Quantity,Order_Date,
Order_Amount,Payment_ID,Payment_Type,Payment_Date,Amount,
Discount_Amount, Invoice_Amount, Customer_ID* )
Product_Details(Product_ID* , Order_ID*)
Order_2(Order_ID,Order_Name,Order_Quantity,Order_Date,
Order_Amount,Payment_ID,Payment_Type,Payment_Date,Amount,
Discount_Amount, Invoice_Amount, Customer_ID* )
Product_2(Product_ID,Product_Name,Product_Desc,Product_Category,
Product_Price,Stock_Quantity,Stock_Level,Vendor_ID,Vendor_Name,
Vendor_Contact, Vendor_Address, Order_ID*, Customer_ID*)
Arpan Karki 13
CC5051NT Databases
Customer(Customer_ID,Customer_Name,Customer_Address,
Customer_Cat_ID*)
Customer_Category(Customer_Cat_ID,Customer_Cat_Type, Discount)
Payment_ID*, Invoive_ID*)
Payment(Payment_ID,Payment_Type,Payment_Date,Payment_Amount,
Discount_Amount)
Arpan Karki 14
CC5051NT Databases
Product(Product_ID,Product_Name,Product_Desc,Product_Price,
Category_ID*, Inventory_ID*, Vendor_ID*)
Product_3(Product_ID,Product_Name,Product_Desc,Product_Price,
Category_ID*, Vendor_ID*)
Order_3(Order_ID,Order_Name,Order_Date,Order_Quantity,
Unit_Price,Total_Amount, Customer_ID*, Payment_ID*, Invoice_ID*)
Arpan Karki 15
CC5051NT Databases
4. Final ERD
The ERD for the online store comprises nine vital entities like customers, products,
orders, and vendors etc. The "order_details" bridge entity plays a key role, in
connecting and organizing these entities to ensure a well-structured database while
minimizing the chances of data redundancy and anomalies.
Arpan Karki 16
CC5051NT Databases
5. Database Implementation
Creation of Database
Creating tables
Once the normalization process is complete, and the final Entity-Relationship
Diagram (ERD) for the database has been designed, the next step involves
implementing it by creating individual tables for each entity and defining various
columns within these tables to represent the attributes of each entity.
Where,
table_name : name of the table
column_1 and colum_2 : name of the column
data_type: NUMBER, VARCHAR, DATE etc.
column_constraint: NOT NULL, UNIQUE, AUTO_INCREMENT etc.
table_constraint: PRIMARY KEY, FOREIGN KEY, CHECK
Different tables that are created are shown below along with their description: -
Arpan Karki 17
CC5051NT Databases
Customer_Address VARCHAR2(255),
Customer_Contact VARCHAR2(15),
);
Customer_Cat_Type VARCHAR(50),
Discount NUMBER
Arpan Karki 18
CC5051NT Databases
);
Product_Cat_Type VARCHAR(50)
);
Arpan Karki 19
CC5051NT Databases
Vendor_Name VARCHAR(255),
Vendor_Contact VARCHAR(15),
Vendor_Address VARCHAR(255)
);
Arpan Karki 20
CC5051NT Databases
Arpan Karki 21
CC5051NT Databases
Invoice_Date DATE,
Invoice_Amount float
);
Arpan Karki 22
CC5051NT Databases
Payment_Type VARCHAR(50),
Payment_Date DATE,
Payment_Amount float,
Discount_Amount float
);
Arpan Karki 23
CC5051NT Databases
Product_Name VARCHAR(255),
Stock_Level INT,
Product_Desc VARCHAR(255),
Product_Price float,
);
Arpan Karki 24
CC5051NT Databases
Order_Name VARCHAR(255),
Order_Date DATE,
Order_Quantity INT,
Unit_Price float,
Total_Amount float,
);
Arpan Karki 25
CC5051NT Databases
Arpan Karki 26
CC5051NT Databases
Arpan Karki 27
CC5051NT Databases
Arpan Karki 28
CC5051NT Databases
Arpan Karki 29
CC5051NT Databases
Arpan Karki 30
CC5051NT Databases
Arpan Karki 31
CC5051NT Databases
VALUES (2, 'Laptop Pro', 'Powerful laptop with advanced features', 1299.99, 2,
2, 2)
INTO Product (Product_ID, Product_Name, Product_Desc, Product_Price,
Product_Cat_ID, Inventory_ID,
Vendor_ID)
VALUES (3, 'Wireless Earbuds', 'Bluetooth earbuds with noise cancellation',
99.99, 3, 3, 3)
INTO Product (Product_ID, Product_Name, Product_Desc, Product_Price,
Product_Cat_ID, Inventory_ID,
Vendor_ID)
VALUES (4, 'Tablet Lite', 'Compact tablet for everyday use', 299.99, 1, 1, 1)
INTO Product (Product_ID, Product_Name, Product_Desc, Product_Price,
Product_Cat_ID, Inventory_ID,
Vendor_ID)
VALUES (5, 'Gaming Laptop', 'High-performance laptop for gaming
enthusiasts', 1799.99, 2, 2, 2)
INTO Product (Product_ID, Product_Name, Product_Desc, Product_Price,
Product_Cat_ID, Inventory_ID,
Vendor_ID)
VALUES (6, 'Bluetooth Speaker', 'Portable speaker with crystal-clear sound',
49.99, 3, 3, 3)
INTO Product (Product_ID, Product_Name, Product_Desc, Product_Price,
Product_Cat_ID, Inventory_ID,
Vendor_ID)
VALUES (7, 'Smartwatch Pro', 'Feature-rich smartwatch with health tracking',
129.99, 1, 1, 1)
SELECT 1 FROM dual;
Arpan Karki 32
CC5051NT Databases
Arpan Karki 33
CC5051NT Databases
Arpan Karki 34
CC5051NT Databases
Arpan Karki 35
CC5051NT Databases
Arpan Karki 36
CC5051NT Databases
Arpan Karki 37
CC5051NT Databases
6. Database Querying
Informational Queries
1. List all the customers that are also staff of the company.
SELECT CUSTOMER_ID, CUSTOMER_NAME, CUSTOMER_ADDRESS,
CUSTOMER_CONTACT
FROM CUSTOMER
WHERE CUSTOMER_CAT_ID IN (
SELECT CUSTOMER_CAT_ID
FROM CUSTOMER_CAT
WHERE CUSTOMER_CAT_TYPE = 'Staff'
);
2. List all the orders made for any particular product between the dates 01-05-2023
till 28- 05-2023.
SELECT
FROM orders
WHERE ORDER_DATE BETWEEN TO_DATE ('2023-05-01', "YYYY"MM-DD')
AND TO_DATE ('2023-05-28', "YYYY-MM-DD');
Arpan Karki 38
CC5051NT Databases
3. List all the customers with their order details and the customers who have not
ordered any products yet.
SELECT
C. CUSTOMER_ID,
C. CUSTOMER_NAME,
o. ORDER_ID,
p. PRODUCT_ID,
p. PRODUCT_ NAME FROM
customer c
LEFT JOIN
orders o ON c.CUSTOMER_ID = o. CUSTOMER_ID
LEFT JOIN
order _details od ON o. ORDER_ID = od.ORDER_ID
LEFT JOIN
product p ON od. PRODUCT_ID = p. PRODUCT_ID;
Arpan Karki 39
CC5051NT Databases
Arpan Karki 40
CC5051NT Databases
4. List all product details that have the second letter ‘a’ in their product name and
have a stock quantity more than 50.
Arpan Karki 41
CC5051NT Databases
Arpan Karki 42
CC5051NT Databases
Transactional query
1. Show the total revenue of the company for each month.
SELECT TO_CHAR(0. ORDER DATE, 'VYYY-MM') AS Month,
SUM(o. TOTAL_AMOUNT) AS TotalRevenue
FROM ORDERS o
GROUP BY TO_CHARO. ORDER_DATE, "MYY-MM')
ORDER BY Month;
2. Find those orders that are equal or higher than the average order total value.
SELECT *
FROM orders
WHERE TOTAL AMOUNT >=
SELECT AVG (TOTAL_AMOUNT)
FROM orders
);
Arpan Karki 43
CC5051NT Databases
3. List all the customers with their order details and also the customers who have
not ordered any products yet.
SELECT
C. Customer_ID,C. Customer _Name,C. Customer_Address,C. customer
_Contact,0. Order_ID,0. Order _Name,
TO_CHAR(O.Order_Date,'DD-MON-YY") AS Order_Date,
o. Order _Quantity,
o. Unit_ Price,
O. Total_Amount
FROM
Customer C
LEFT JOIN
Orders O ON C.Customer_ID = 0. Customer_ID
ORDER BY
C. Customer _ID, 0.0rder_ID;
Arpan Karki 44
CC5051NT Databases
4. Show the top 3 product details that have been ordered the most.
SELECT v. VendorfId, v. Vendor_Name, COUNT (p. Product_Id) AS
ProductsSupplied
FROM Vendor v
JOIN Product p ON v. Vendor_Id = p. Vendor_Id
GROUP BY v. Vendor_Id, v. Vendor_Name
HAVING COUNT (p.Product_Id) › 3;
Arpan Karki 45
CC5051NT Databases
5. Find out the customer who has ordered the most in August with his/her total
spending on that month.
SELECT * FROM (
SELECT c. Customer_ID, c. Customer_Name, MAX(o.UNIT_PRICE * 0.
ORDER_QUANTITY) AS Total_Spending
FROM Customer c
JOIN Orders o ON c. Customer_ID = o. Customer_ID
WHERE
EXTRACT (MONTH FROM o. Order_Date) = 8
GROUP BY
c. Customer__ID, c. Customer_Name
ORDER BY Total_Spending DESC )
WHERE ROWNUM = 1;
Arpan Karki 46
CC5051NT Databases
7. File Creation
Arpan Karki 47
CC5051NT Databases
Arpan Karki 48
CC5051NT Databases
Arpan Karki 49
CC5051NT Databases
strain the company's financial resources. The complexity of the system necessitates a
skilled workforce, requiring significant investment in training and development. The
development journey of the Gadget Emporium database was not without its hurdles. One
of the primary challenges was the identification of appropriate entities and attributes. The
intricate relationships between different entities, especially in the context of many-to-
many relationships, demanded a thoughtful normalization strategy. Crafting transactional
queries that align with both informational and business logic requirements posed a
considerable challenge. Additionally, ensuring data integrity and optimizing queries for
maximum performance were continuous tasks that required meticulous attention. To
tackle these challenges, collaboration emerged as a key factor. Guidance from our
module teacher provided invaluable insights into the selection of entities and attributes.
Research efforts, both online and within the academic community, played a pivotal role in
addressing many-to-many relationships through normalization techniques. The
introduction of junction tables to resolve complex relationships showcased the
adaptability of the database design.
In conclusion, the journey of crafting the database for Gadget Emporium has been quite
the adventure, aimed at making our business smoother and our customer’s experience
top-notch. We took the route of using a relational database management system
(RDBMS) to keep things structured and organized, ensuring that data about our
customers, vehicles, drivers, services, and prices is at our fingertips whenever we need
it. Our database's main goal is to make sure our operations run like a well-oiled machine
and our customers can easily access our services. It's not just a behind-the-scenes hero;
it's also the backbone of our website and app, allowing customers to check their bookings,
payment details, and more. Security was a top concern, so we made sure to lock down
our data with encryption and regular backups, protecting it like a treasure. On the bright
side, our database has brought order to our information chaos. It's the go-to place for
quick and efficient data retrieval. But, like any superhero, it has its challenges. Setting it
up and keeping it running can be a bit heavy on the pocket, and the complexity means
we need a skilled team to handle it.
Arpan Karki 50
CC5051NT Databases
Crafting this database came with its fair share of puzzles. Figuring out what entities and
attributes to include was like solving a jigsaw puzzle. Tackling relationships between
different bits of data, especially those tricky many-to-many relationships, needed a bit of
magic called normalization. Creating queries that make sense to both computers and
humans took time, and ensuring data behaves itself was a marathon.
We didn’t do it alone – our module teacher’s guidance and some good old online research
were our trusty sidekicks. To handle the complicated relationships, we brought in junction
tables as our secret weapon. These tables acted as bridges between different pieces of
information. In the end, the Gadget Emporium database is our silent hero, organizing,
securing, and making our business smarter. Yes, it has its quirks and costs, but it’s an
investment in a smoother future. Learning from our challenges, we’re ready to adapt and
grow, making our database not just a tool but a partner in our journey. In the ever-evolving
world of technology, our database stands as a testament to our commitment to delivering
top-notch services, backed by a system that's as dynamic as we are.
Arpan Karki 51
CC5051NT Databases
References
Chen, 2023. codingninjas. [Online]
Available at: https://www.codingninjas.com/studio/library/entity-and-attributes
[Accessed 23 12 2023].
John, 2023. herovired. [Online]
Available at: https://herovired.com/learning-hub/blogs/difference-between-primary-key-
and-foreign-key/
[Accessed 23 12 2023].
Jones, S., 2023. MindManager. [Online]
Available at: https://blog.mindmanager.com/how-to-write-business-rules/
[Accessed 20 12 2023].
Ravikiran, 2023. Simplelearn. [Online]
Available at: https://www.simplilearn.com/tutorials/sql-tutorial/what-is-normalization-in-
sql
[Accessed 1 1 2023].
Arpan Karki 52