Download as pdf or txt
Download as pdf or txt
You are on page 1of 56

Module Code & Module Title

CC5051NT Databases

Assessment Weightage & Type 50%


Individual Coursework

Year: 2023-24
Semester: 3rd Semester

Student Name: Arpan Karki


Group: L2C2
London Met ID: 22072096
College ID: NP05CP4220024
Assignment Submission Date: 15th January, 2023

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

Introduction of the business ......................................................................................... 1

Current Business Activities and Operations ................................................................. 2

Business Rules ............................................................................................................ 3

2. Initial ERD ................................................................................................................. 5

Identification of entities and attributes .......................................................................... 5

Identification and representation of the Primary Keys, Foreign Keys ........................... 8

Initial ERD .................................................................................................................... 9

3. Normalization .......................................................................................................... 11

Unnormalized Form ................................................................................................... 11

First Normal Form (1NF) ............................................................................................... 11

Final First Number Form (1NF) ..................................................................................... 12

Second Normal Form (2NF) ....................................................................................... 12

Final Second Number Form (2NF) ............................................................................. 13

Third Normal Form (3NF)........................................................................................... 14

Final Third Normal Form (3NF) ..................................................................................... 15

4. Final ERD ............................................................................................................... 16

5. Database Implementation ....................................................................................... 17

Creation of Database ................................................................................................. 17

Creating tables........................................................................................................... 17

Populating tables of Database ................................................................................... 28

6. Database Querying ................................................................................................. 38

Informational Queries................................................................................................. 38
Transactional query ................................................................................................... 43

7. File Creation .............................................................................................................. 47

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.

The objectives of Gadget Emporium are as follows:

➢ 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.

Current Business Activities and Operations


The business activities that the company has been conducting are as follows:

i. Provide a wide selection of electronics, including game consoles,


computers, cellphones, cameras, and other tech accessories.
ii. Operate an easy-to-navigate e-commerce website that allows customers to
browse, select, and purchase products effortlessly.
iii. Make sure that financial transactions are safe by using reliable and secure
payment gateways.
iv. Efficiently process customer orders, from the point of purchase to the
shipment of products.
v. Maintain real-time updates on product availability to prevent customers from
ordering out-of-stock items.
vi. Require customers to register on the platform, capturing essential
information for order processing and communication.
vii. Offer special discounts for business organizations placing bulk orders,
encouraging larger transactions.
viii. Provide customers, both individual and business, with order tracking
features for transparency and real-time updates.
ix. Prioritize fast and reliable delivery services to ensure customer satisfaction
and prompt receipt of orders.
x. Engage with customers through various communication channels,
addressing queries, and ensuring a positive shopping experience.
xi. Cultivate strong relationships with vendors to ensure a consistent supply of
high-quality products for the online marketplace.
xii. Provide responsive and helpful customer support services to address
inquiries, and concerns, and enhance overall customer satisfaction.
xiii. Create detailed and accurate product descriptions to assist customers in
making informed purchasing decisions.

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)

Following are a few of "Gadget Emporium's" business rules: -

1. Product Management Rules:


➢ Each product must have a unique identifier (ProductID).
➢ Product names, descriptions, categories, prices, and stock levels must be
recorded.
➢ Each product belongs to only one category, and each category can have
one or many products.
2. Customer Categorization and Discounts:
➢ Customers are categorized as Regular (R), Staff (S), or VIP (V).
➢ Each customer category is entitled to a different discount rate on product
purchases (0%, 5%, 10%).
➢ Customer addresses must be stored for delivery purposes.

Arpan Karki 3
CC5051NT Databases

3. Order Processing Rules:


➢ Each order must have a unique identifier (OrderID).
➢ Order details, including the products purchased, quantities, unit prices, and
total order amount, must be recorded.
➢ An order can contain multiple products, and one type of product can be
included in multiple orders.
4. Vendor Management Rules:
➢ Vendor information, including vendor names, contact persons, and contact
details, must be maintained.
➢ Each product is associated with a single vendor.
➢ Each vendor can supply one or more products.
5. Product Availability and Inventory Management:
➢ Real-time product availability must be tracked to prevent overselling.
➢ Each product must have inventory details like stock quantity or availability
status.
6. Payment Processing Rules:
➢ The system must integrate with various payment gateways.
➢ Payment options include cash on delivery, credit/debit card, or e-wallet.
➢ Each order detail must have one payment option.
7. Invoice Issuance Rules:
➢ An invoice must be issued once the customer checks out their order.
➢ The invoice must include details of the order, customer, and payment (with
discount).
8. Unique Identifiers:
➢ Each customer must have a unique identifier (CustomerID).
➢ Each vendor must have a unique identifier (VendorID).

Arpan Karki 4
CC5051NT Databases

9. Security and Privacy:


➢ Customer information, including addresses and contact details, must be
stored securely.
➢ Vendors contact details and product pricing information must be kept
confidential.
10. Discount Calculation:
➢ The discount amount for each customer must be calculated based on their
category.
11. Payment Validation:
➢ Payment details must be validated before completing the order.
12. Order Total Calculation:
➢ The total amount for each order must be calculated based on the quantity
and unit price of products, considering any applicable discounts.
13. Consistency in Data Entry:
➢ Data entry for products, customers, orders, and vendors must be consistent
and follow predefined formats to ensure accuracy.

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 entity and its attributes


Table 1 : Product attributes and their description

Product

Attributes Description

Product_ID (PK) Unique ID for Product

Product_Name Name of the Product

Product_Desc Description of the Product

Product_Category Category of the product

Product_Price Price of the Product

Stock_level Price of the Product

Customer entity and its attributes


Table 2 : Customer attributes and their description

Customer

Attributes Description

Customer_ID (PK) Unique ID for Customer

Customer_Name Name of the customer

Customer_Contact Contact Details of the customer

Customer_Address Address of customer

Arpan Karki 6
CC5051NT Databases

Customer_Cat_ID Unique ID for Customer Category

Customer_Cat_Type Type of Category (Regular,Staff,VIP)

Discount_Rate Type of Rate (0%,5%,10%)

Order entity and attributes

Table 3 : Order attributes with their description

Order

Attributes Description

Order_ID (PK) Unique ID for Order

Order_Name Order Name for Order

Order_Amount Order Amount for Order

Order_Date Order Date for Order

Order Quantity for Order


Order_Quantity

Unit Price Unit Price for Order

Payment_ID Unique ID for payment

Payment_Type Type of payment

Payment_Amount Amount of payment

Arpan Karki 7
CC5051NT Databases

Discount_Amount Amount of Discount

Invoice_ID Unique ID for Invoice

Invoive_Date Date of Invoice

Invoive_Amount Amount of Invoice

Vendor entity and attributes

Table 4 : Vendor attributes with their description

Vendor

Attributes Description

Vendor_ID (PK) Unique ID for Vendor

Vendor_Name Name of the Vendor

Vendor_Contact Vendor Contact Information

Vendor_Address Vendor Address Information

Identification and representation of the Primary Keys, Foreign Keys


A primary key is a unique identifier for each record in a table.
A foreign key establishes a relationship between tables by referencing the primary
key of another table. (John, 2023)
The table provided outlines the primary and foreign keys associated with the
various entities identified within the database of Gadget Emporium.

Arpan Karki 8
CC5051NT Databases

Entity Primary Key Foreign Key Reference Table Reference Column

Vendor Vendor_ID Product_ID Product Product_ID

Product Product_ID Vendor_ID Vendor Vendor_ID

Customer Customer_ID _ _ _

Order Order_ID Product_ID Product Product_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.

Orders: Transactions initiated by customers. Orders and customers are connected


in a many-to-many relationship, where each order is placed by a customer, and a
customer can place multiple orders.

Vendors: Companies supplying products to the Gadget Emporium online store.


Vendors and products are linked in a one-to-many relationship. A vendor can
supply multiple products, but each product is associated with a single vendor.

Arpan Karki 9
CC5051NT Databases

Figure 1 : Initial ERD

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 }})

First Normal Form (1NF)


In the first normal form, we organize the repeating groups identified in the
Unnormalized Form (UNF) by placing them into separate entities or tables. These
entities are then given a primary key.

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*)

Final First Number Form (1NF)


Customer_1(Customer_ID,Customer_Name,Customer_Address,
Customer_Contact, Customer_Cat_ID,Customer_Cat_Type, Discount_Rate)

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*)

Second Normal Form (2NF)


In Second Normal Form (2NF), the focus is on identifying and resolving partial
functional dependencies within a table. The table is assessed for partial
dependency due to its composite primary key (Product_ID, Order_ID).

Arpan Karki 12
CC5051NT Databases

Checking and removing partial functional dependency.

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*)

Final Second Number Form (2NF)


Customer_2(Customer_ID,Customer_Name,Customer_Address,
Customer_Contact,Customer_Cat_ID,Customer_Cat_Type, Discount_Type)

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*)

Product_Details_2 (Product_ID* , Order_ID*)

Arpan Karki 13
CC5051NT Databases

Third Normal Form (3NF)


In the process of achieving Third Normal Form (3NF), we examine each table
derived from the Second Normal Form (2NF) to identify and eliminate transitive
dependencies. This step is crucial for refining the database structure and ensuring
that data dependencies are appropriately organized to minimize redundancy and
improve overall normalization.

Checking transitive dependency on the customer:

Customer_ID → Customer_Cat_ID → Customer_Cat_Type, Discount

Customer(Customer_ID,Customer_Name,Customer_Address,
Customer_Cat_ID*)

Customer_Category(Customer_Cat_ID,Customer_Cat_Type, Discount)

Checking transitive dependency on Order:

Order_ID → Payment_ID → Payment_Type, Payment_Date, Discount_Amount,


Payment_Amount

Order_ID → Invoice_ID → Invoice_Date, Invoice_Amount

Order ( Order_ID, Order_Name, Order_Date, Order_Quantity, Unit_Price,

Payment_ID*, Invoive_ID*)

Payment(Payment_ID,Payment_Type,Payment_Date,Payment_Amount,
Discount_Amount)

Invoice (Invoive_ID, Invoive_Date, Invoice_Amount)

Arpan Karki 14
CC5051NT Databases

Checking transitive dependency on the product.

Product_ID → Product_Cat_ID → Product_Cat_Type

Product_ID → Vendor_ID → Vendor_Name, Vendor_Contact, Vendor_Address)

Product(Product_ID,Product_Name,Product_Desc,Product_Price,
Category_ID*, Inventory_ID*, Vendor_ID*)

Product_Category (Product_Cat_ID, Product_Cat_Type) bnb

Vendor (Vendor_ID, Vendor_Name, Vendor_Contact, Vendor_Address)

Final Third Normal Form (3NF)


Customer_3(Customer_ID,Customer_Name,Customer_Address,
Customer_Contact, Customer_Cat_ID*)

Customer_Cat_3 (Customer_Cat_ID, Customer_Cat_Type,Discount)

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*)

Payment_3 (Payment_ID, Payment_Type, Payment_Date, Payment_Amount,


Discount_Amount)

Invoice_3 (Invoice_ID, Invoice_Date, Invoice_Amount)

Product_Cat_3 (Product_Cat_ID, Product_Cat_Type)

Vendor_3 (Vendor_ID, Vendor_Name, Vendor_Contact, Vendor_Address)

Order_Details_3 (Product_ID*, Order_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.

Figure 2 : Final ERD

Arpan Karki 16
CC5051NT Databases

5. Database Implementation
Creation of Database

Figure 3 : User creation

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: -

Table for Customer

CREATE TABLE Customer (

Arpan Karki 17
CC5051NT Databases

Customer_ID INT PRIMARY KEY, Customer_Name VARCHAR2(255),

Customer_Address VARCHAR2(255),

Customer_Contact VARCHAR2(15),

Customer_Cat_ID INT REFERENCES Customer_Cat(Customer _Cat _ID)

);

Figure 4 : Creation table for Customer

Figure 5 : Customer table description

Table for Customer_Cat

CREATE TABLE Customer_Category (

Customer_Cat_ID INT PRIMARY KEY,

Customer_Cat_Type VARCHAR(50),

Discount NUMBER

Arpan Karki 18
CC5051NT Databases

);

Figure 6 : Creating table for Customer Category

Figure 7 : Customer Category table description

Table for Product_Cat

CREATE TABLE Product_Cat (

Product_Cat_ID INT PRIMARY KEY,

Product_Cat_Type VARCHAR(50)

);

Arpan Karki 19
CC5051NT Databases

Figure 8 : Creating table for Product Category

Figure 9 : Product category table description

Table for Vendor

CREATE TABLE Vendor (

Vendor_ID INT PRIMARY KEY,

Vendor_Name VARCHAR(255),

Vendor_Contact VARCHAR(15),

Vendor_Address VARCHAR(255)

);

Arpan Karki 20
CC5051NT Databases

Figure 10 : Creating table for Vendor.

Figure 11 : Vendor table description

Arpan Karki 21
CC5051NT Databases

Table for Invoice

CREATE TABLE Invoice (

Invoice_ID INT PRIMARY KEY,

Invoice_Date DATE,

Invoice_Amount float

);

Figure 12 : Creating table for Invoice

Figure 13 : Invoice table description

Table for Payment

CREATE TABLE Payment (

Arpan Karki 22
CC5051NT Databases

Payment_ID INT PRIMARY KEY,

Payment_Type VARCHAR(50),

Payment_Date DATE,

Payment_Amount float,

Discount_Amount float

);

Figure 14 : Creating table for Payment

Figure 15 : Payment table description

Arpan Karki 23
CC5051NT Databases

Table for Product

CREATE TABLE Product (

Product_ID INT PRIMARY KEY,

Product_Name VARCHAR(255),

Stock_Level INT,

Product_Desc VARCHAR(255),

Product_Price float,

Category_ID INT REFERENCES Product_Cat(Product_Cat_ID),

Vendor_ID INT REFERENCES Vendor(Vendor_ID)

);

Figure 16 : Create table for product

Arpan Karki 24
CC5051NT Databases

Figure 17 : Product table description

Table for Order

CREATE TABLE Orders (

Order_ID INT PRIMARY KEY,

Order_Name VARCHAR(255),

Order_Date DATE,

Order_Quantity INT,

Unit_Price float,

Total_Amount float,

Customer_ID INT REFERENCES Customer(Customer_ID),

Payment_ID INT REFERENCES Payment(Payment_ID),

Invoice_ID INT REFERENCES Invoice(Invoice_ID)

);

Arpan Karki 25
CC5051NT Databases

Figure 18 : Creating table for Orders

Figure 19 : Order table description

Table for Order_Details


CREATE TABLE Order_Details (

Arpan Karki 26
CC5051NT Databases

Order_Details_ID INT PRIMARY KEY,


Product_ID INT REFRENCES Product(Product_ID),
Order_ID INT REFRENCES Orders(Order_ID)
);

Figure 20 : Creating table for Order Details

Figure 21 : Order details description

Arpan Karki 27
CC5051NT Databases

Populating tables of Database


It's time to add data to the tables that created and shown the relationships
between them. To enter data into table, following syntax is used.
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

Inserting data into Customer_Cat table


INSERT ALL
INTO Customer_Cat (Customer_Cat_ID, Customer_Cat_Type, Discount)
VALUES (1, 'Regular', 3)
INTO Customer_Cat (Customer_Cat_ID, Customer_Cat_Type, Discount)
VALUES (2, 'Staff', 5)
INTO Customer_Cat (Customer_Cat_ID, Customer_Cat_Type, Discount)
VALUES (3, 'VIP', 10)
SELECT 1 FROM dual;

Figure 22 : Inserting data into Customer category

Inserting data into Customer table


INSERT ALL
INTO Customer (Customer_ID, Customer_Name, Customer_Address,
Customer_Contact, Customer_Cat_ID)
VALUES (1, 'Arpan Karki', 'Taplejung', '5551234', 1)
INTO Customer (Customer_ID, Customer_Name, Customer_Address,
VALUES (2, 'Sarthak Sherpa', 'Darjelling', '5555678', 2)

Arpan Karki 28
CC5051NT Databases

INTO Customer (Customer_ID, Customer_Name, Customer_Address,


Customer_Contact, Customer_Cat_ID)
VALUES (3, 'Prabin Ghimire', 'Birat Chowk', '5559101', 1)
INTO Customer (Customer_ID, Customer_Name, Customer_Address,
Customer_Contact, Customer_Cat_ID)
VALUES (4, 'Binaya Acharya', 'Inuruwa', '5551122', 3)
INTO Customer (Customer_ID, Customer_Name, Customer_Address,
Customer_Contact, Customer_Cat_ID)
VALUES (5, 'Prshant Tamang', 'Pathri', '5553344', 1)
INTO Customer (Customer_ID, Customer_Name, Customer_Address,
Customer_Contact, Customer_Cat_ID)
VALUES (6, 'Ram Limbu', 'koteshowor', '5555566', 2)
INTO Customer (Customer_ID, Customer_Name, Customer_Address,
Customer_Contact, Customer_Cat_ID)
VALUES (7, 'Rahul shrestha', 'Taltalaya', '5557788', 3)
SELECT 1 FROM dual;

Figure 23 : Inserting data into Customer

Inserting data into Product_Cat table


INSERT ALL

Arpan Karki 29
CC5051NT Databases

INTO Product_Cat (Product_Cat_ID, Product_Cat_Type) VALUES (1,


'Smartphones')
INTO Product_Cat (Product_Cat_ID, Product_Cat_Type) VALUES (2,
'Laptops')
INTO Product_Cat (Product_Cat_ID, Product_Cat_Type) VALUES (3, 'Audio
Devices')
SELECT 1 FROM dual;

Figure 24 : Inserting data into Product Category table

Inserting data into Vendor table


INSERT ALL
INTO Vendor (Vendor_ID, Vendor_Name, Vendor_Contact, Vendor_Address)
VALUES (1, 'TechWorld', '9811400122', 'Damak')
INTO Vendor (Vendor_ID, Vendor_Name, Vendor_Contact, Vendor_Address)
VALUES (2, 'Gadget Haven', '9822028291', 'Dharan')
INTO Vendor (Vendor_ID, Vendor_Name, Vendor_Contact, Vendor_Address)
VALUES (3, 'ElectroTech', '9712727171', 'Dulari')
INTO Vendor (Vendor_ID, Vendor_Name, Vendor_Contact, Vendor_Address)
VALUES (4, 'Appliance Universe', '1234567890', 'Cityville')
INTO Vendor (Vendor_ID, Vendor_Name, Vendor_Contact, Vendor_Address)
VALUES (5, 'Digital Solutions', '9876543210', 'Tech Lane')
INTO Vendor (Vendor_ID, Vendor_Name, Vendor_Contact, Vendor_Address)
VALUES (6, 'Innovative Electronics', '8765432109', 'Innovation Street')

Arpan Karki 30
CC5051NT Databases

INTO Vendor (Vendor_ID, Vendor_Name, Vendor_Contact, Vendor_Address)


VALUES (7, 'Tech Innovators', '7654321098', 'Tech Avenue')
SELECT 1 FROM dual;

Figure 25 : Inserting data into vendor table

Inserting data into Product table


INSERT ALL
INTO Product (Product_ID, Product_Name, Product_Desc, Product_Price,
Product_Cat_ID, Inventory_ID,
Vendor_ID)
VALUES (1, 'Smartphone X', 'A high-end smartphone', 799.99, 1, 1, 1)
INTO Product (Product_ID, Product_Name, Product_Desc, Product_Price,
Product_Cat_ID,Inventory_ID, Vendor_ID)

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

Figure 26 : Inserting data into product table

Inserting data into Payment table


INSERT ALL
INTO Payment (Payment_ID, Payment_Type, Payment_Date,
Payment_Amount, Discount_Amount) VALUES (1, 'Credit
Card', TO_DATE('2023-06-01', 'YYYY-MM-DD'), 500.00, 50.00)
INTO Payment (Payment_ID, Payment_Type, Payment_Date, Payment_Amount,
Discount_Amount) VALUES (2, 'Cash on Delivery', TO_DATE('2023-06-02',
'YYYY-MM-DD'), 800.00, 80.00)
INTO Payment (Payment_ID, Payment_Type, Payment_Date,
Payment_Amount, Discount_Amount) VALUES (3, 'E-
wallet', TO_DATE('2023-06-03', 'YYYY-MM-DD'), 1200.00, 120.00)
INTO Payment (Payment_ID, Payment_Type, Payment_Date,
Payment_Amount, Discount_Amount) VALUES (4, 'Credit
Card', TO_DATE('2023-06-04', 'YYYY-MM-DD'), 1500.00, 150.00)

Arpan Karki 33
CC5051NT Databases

INTO Payment (Payment_ID, Payment_Type, Payment_Date,


Payment_Amount, Discount_Amount) VALUES (5, 'Cash
on Delivery', TO_DATE('2023-06-05', 'YYYY-MM-DD'), 300.00, 30.00)
INTO Payment (Payment_ID, Payment_Type, Payment_Date,
Payment_Amount, Discount_Amount) VALUES (6, 'E-
wallet', TO_DATE('2023-06-06', 'YYYY-MM-DD'), 600.00, 60.00)
INTO Payment (Payment_ID, Payment_Type, Payment_Date,
Payment_Amount, Discount_Amount) VALUES (7, 'Credit
Card', TO_DATE('2023-06-07', 'YYYY-MM-DD'), 900.00, 90.00)
SELECT 1 FROM dual;

Figure 27 : Inserting data into Payment table

Inserting data into Invoice table


INSERT ALL
INTO Invoice (Invoice_ID, Invoice_Date, Invoice_Amount)
VALUES (101, TO_DATE('2023-06-01', 'YYYY-MM-DD'),450.00)
INTO Invoice (Invoice_ID, Invoice_Date, Invoice_Amount)
VALUES (102, TO_DATE('2023-06-02', 'YYYY-MM-DD'),720.00)
INTO Invoice (Invoice_ID, Invoice_Date, Invoice_Amount)
VALUES (103, TO_DATE('2023-06-03', 'YYYY-MM-DD'),1080.00)

Arpan Karki 34
CC5051NT Databases

INTO Invoice (Invoice_ID, Invoice_Date, Invoice_Amount)


VALUES (104, TO_DATE('2023-06-04', 'YYYY-MM-DD'),1350.00)
INTO Invoice (Invoice_ID, Invoice_Date, Invoice_Amount)
VALUES (105, TO_DATE('2023-06-05', 'YYYY-MM-DD'),270.00)
INTO Invoice (Invoice_ID, Invoice_Date, Invoice_Amount)
VALUES (106, TO_DATE('2023-06-06', 'YYYY-MM-DD'),540.00)
INTO Invoice (Invoice_ID, Invoice_Date, Invoice_Amount)
VALUES (107, TO_DATE('2023-06-07', 'YYYY-MM-DD'),810.00)
SELECT 1 FROM dual;

Figure 28 : Inserting data into Invoice table

Inserting data into Orders table


INSERT ALL
INTO Orders (Order_ID, Order_Name, Order_Date, Order_Quantity,
Unit_Price, Total_Amount, Customer_ID, Payment_ID, Invoice_ID)
VALUES (201, 'Order 201', TO_DATE('2023-06-01', 'YYYY-MM-DD'), 2,
399.99, 799.98, 1, 3, 101)
INTO Orders (Order_ID, Order_Name, Order_Date, Order_Quantity,
Unit_Price, Total_Amount, Customer_ID, Payment_ID, Invoice_ID)
VALUES (202, 'Order 202', TO_DATE('2023-06-02', 'YYYY-MM-DD'), 1,
1299.99, 1299.99, 2, 2, 102)

Arpan Karki 35
CC5051NT Databases

INTO Orders (Order_ID, Order_Name, Order_Date, Order_Quantity,


Unit_Price, Total_Amount, Customer_ID, Payment_ID, Invoice_ID)
VALUES (203, 'Order 203', TO_DATE('2023-06-03', 'YYYY-MM-DD'), 3,
299.99, 899.97, 3, 2, 103)
INTO Orders (Order_ID, Order_Name, Order_Date, Order_Quantity,
Unit_Price, Total_Amount, Customer_ID, Payment_ID, Invoice_ID)
VALUES (204, 'Order 204', TO_DATE('2023-06-04', 'YYYY-MM-DD'), 2,
699.99, 1399.98, 4, 3, 104)
INTO Orders (Order_ID, Order_Name, Order_Date, Order_Quantity,
Unit_Price, Total_Amount, Customer_ID, Payment_ID, Invoice_ID)
VALUES (205, 'Order 205', TO_DATE('2023-06-05', 'YYYY-MM-DD'), 1,
1799.99, 1799.99, 5, 1, 105)
INTO Orders (Order_ID, Order_Name, Order_Date, Order_Quantity,
Unit_Price, Total_Amount, Customer_ID, Payment_ID, Invoice_ID)
VALUES (206, 'Order 206', TO_DATE('2023-06-06', 'YYYY-MM-DD'), 2, 49.99,
99.98, 6, 2, 106)
INTO Orders (Order_ID, Order_Name, Order_Date, Order_Quantity,
Unit_Price, Total_Amount, Customer_ID, Payment_ID, Invoice_ID)
VALUES (207, 'Order 207', TO_DATE('2023-06-07', 'YYYY-MM-DD'), 1,
129.99, 129.99, 7, 3, 107)
SELECT 1 FROM dual;

Figure 29 : Inserting data into Order table

Arpan Karki 36
CC5051NT Databases

Inserting data into Orders_Details table


INSERT ALL
INTO Order_Details (Order_Details_ID, Product_ID, Order_ID) VALUES (1, 1,
201)
INTO Order_Details (Order_Details_ID, Product_ID, Order_ID) VALUES (2, 2,
202)
INTO Order_Details (Order_Details_ID, Product_ID, Order_ID) VALUES (3, 3,
203)
INTO Order_Details (Order_Details_ID, Product_ID, Order_ID) VALUES (4, 4,
204)
INTO Order_Details (Order_Details_ID, Product_ID, Order_ID) VALUES (5, 5,
205)
INTO Order_Details (Order_Details_ID, Product_ID, Order_ID) VALUES (6, 6,
206)
INTO Order_Details (Order_Details_ID, Product_ID, Order_ID) VALUES (7, 7,
207)
SELECT 1 FROM dual;

Figure 30 : Inserting data into Order_Details table

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'
);

Figure 31 : Informational query 1

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

Figure 32 : Informational query 2

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

Figure 33 : Informational query 3

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.

SELECT * FROM Product


WHERE Product_Name LIKE '_a%'
AND Stock_Level › 50;

Figure 34 : Informational query 4

5. Find out the customer who has ordered recently.


SELECT
*
FROM (
SELECT
C. Customer_ID,
C. Customer_Name,
0.Order_ID,
0.Order_Name,
0.Order_Date
FROM
Customer C
JOIN
Orders O ON C. Customer_ID = 0. Customer_ID
ORDER BY
0.Order_Date DESC
WHERE ROWNUM = 1;

Arpan Karki 41
CC5051NT Databases

Figure 35 : Informational query 5

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;

Figure 36 : Transactional query 1

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

Figure 37 : Transactional query 2

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

Figure 38 : Transactional query 3

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

Figure 39 : Transactional query 4

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;

Figure 40 : Transactional query 5

Arpan Karki 46
CC5051NT Databases

7. File Creation

Figure 41 : Command to create dump file

Arpan Karki 47
CC5051NT Databases

Figure 42 : Exporting database to a dump file

Arpan Karki 48
CC5051NT Databases

Figure 43 : Proof of dump file creation

7. Critical Evaluation and Conclusion


The development and implementation of the database for Gadget Emporium, a dynamic
business encompassing diverse services like food delivery, package delivery, and rides,
have been a transformative endeavor. Utilizing a relational database management
system (RDBMS) as the backbone, the database aims to enhance business operations,
customer experiences, and data security. The primary purpose of the Gadget Emporium
database is to orchestrate seamless interactions between customers, vehicles, drivers,
and the myriad services offered. The key objectives include efficient storage and retrieval
of data, secure customer access through web and mobile interfaces, and the ability to
adapt to the evolving needs of the business. Security stands as a paramount
consideration in the Gadget Emporium database. Data encryption protocols have been
implemented, ensuring that sensitive information remains protected against unauthorized
access. The integration of regular data backup mechanisms serves as a safeguard,
providing a restorative layer in case of unexpected data loss or corruption. The
advantages of the Gadget Emporium database are evident in its ability to centralize and
organize business-critical information. Customer interactions are streamlined, and the
database acts as a reliable repository for quick and efficient data retrieval. However, the
implementation of such a comprehensive system is not without its challenges. The
associated costs, both in terms of initial setup and ongoing maintenance, could potentially

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

You might also like