Prabin G.C.

You might also like

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

CC5051NI Databases

50% Individual Coursework

Autumn 2023

Student Name: Prabin G.C.


London Met ID: 22067664
Assignment Submission Date: 14th of January
Word Count: 4877

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 mark of zero will be awarded.
CC5051NI DATABASE

Table of Contents

1.Introduc+on ......................................................................................................................... 1
1.1 Aims and objec0ves of this Coursework. .................................................................................... 1
1.2Tools used in this Coursework. .................................................................................................... 1
1.3 Current Business Ac0vi0es and Opera0ons................................................................................ 3
1.4 Business Rule ............................................................................................................................. 3
1.5 Assump0ons .............................................................................................................................. 4
2. En+ty Rela+onship Diagram ................................................................................................ 4
2.1 ADributes and En0ty .................................................................................................................. 5
2.2 Crea0on of En00es and ADributes.............................................................................................. 5
3. Ini+al ERD ........................................................................................................................... 7
4.Normaliza+on ...................................................................................................................... 8
4.1 UNF (Un-Normalized Form) ........................................................................................................ 8
4.2 1NF (First Normal Form) ................................................................................................................................ 9
4.3 2NF (Second Normal Form) ......................................................................................................................... 10
4.4 3NF (Third Normal Form.............................................................................................................................. 11

5. Final ERD ........................................................................................................................... 12


6. Data Implementa+on ........................................................................................................ 13
6.1 Crea0ng Tables ......................................................................................................................... 13
6.2 Customer ................................................................................................................................. 13
The table of customer aQer normaliza0on: .................................................................................... 13
6.3 Orders ...................................................................................................................................... 15
6.4 Invoice ..................................................................................................................................... 17
6.5 Product .................................................................................................................................... 18
6.6 Vendor ..................................................................................................................................... 19
6.7 Customer Order Product .......................................................................................................... 21
7. Popula+ng the Database tables. ....................................................................................... 22
7.1 INSERTING values into Customer table. .................................................................................... 22
7.2 INSERTING values into Invoice Table. ........................................................................................ 24
7.3 INSERTING values in Orders Table............................................................................................. 26
7.4 INSERTING into Vendor table.................................................................................................... 28
7.5 INSERTING values in Product Table. .......................................................................................... 30
7.6 INSERTING values in Customer_Order_Product Table ............................................................... 32
CC5051NI DATABASE

8. Database Querying ........................................................................................................... 34


8.1 Informa0on Query ................................................................................................................... 34
8.1.1 List all the customers that are also staff of the company. ........................................................................ 34
8.1.2 List all the orders made for any product between the dates 01-05-2023 Gll 28-05-2023. ....................... 34
8.1.3 List all the customers with their order details and the customers who haven’t ordered any products yet.
.......................................................................................................................................................................... 35
8.1.4 List all product details that have the second leJer ‘a’ in their product name and have stock quanGty
more than 50. .................................................................................................................................................... 35
8.1.5 Find out the customer who has ordered recently. DHFibernet@0414435 .............................................. 36
8.2 Transac0on Query .................................................................................................................... 37
8.2.1 Show the total revenue of the company for each month. ....................................................................... 37
8.2.2 Find those orders that are equal or higher than the average order total value. ...................................... 37
8.2.3 List the details of vendors who have supplied more than 3 products to the company. ........................... 38
8.2.5 Find out the customer who has ordered the most in August with his/her total spending on ................. 39
that month. ....................................................................................................................................................... 39

9. Cri+cal Evalua+on ............................................................................................................. 40


9.1 Further Discussion on your learning Experience. ...................................................................... 40
9.2 Cri0cal Evalua0on .................................................................................................................... 41
10.Droping table and dump file crea+on ............................................................................... 42
10.1 Crea0on of Dump File............................................................................................................. 42
10.2 Crea0ng Spool file. ................................................................................................................. 43
10.3 Dropping tables. ..................................................................................................................... 44
11.References ....................................................................................................................... 45
CC5051NI DATABASE

Table of figures
Figure 1: Logo Of Ms-Word.............................................................................................................1
Figure 2:Logo of Draw.io. ................................................................................................................2
Figure 3: Example of SQL PLUS. ......................................................................................................2
Figure 4:IniRal ERD .........................................................................................................................7
Figure 5: Final Normalised ERD.....................................................................................................12
Figure 6: CreaRon of Customer table............................................................................................14
Figure 7:CreaRng Order table. ......................................................................................................16
Figure 8: CreaRng Invoice table. ...................................................................................................17
Figure 9: CreaRng table Product. ..................................................................................................19
Figure 10: CreaRng table Vendor. .................................................................................................20
Figure 11: CreaRng Customer_Order_Product table ....................................................................21
Figure 12: InserRng Values in Customer Table. .............................................................................23
Figure 13: SelecRng from Customer Table. ...................................................................................23
Figure 14: InserRng Values in Invoice Table. .................................................................................25
Figure 15: SelecRng from Invoice. ................................................................................................25
Figure 16:InserRng Values in Orders table. ...................................................................................27
Figure 17:SelecRng From Order table. ..........................................................................................27
Figure 18: INSERTING into Vendor table. ......................................................................................29
Figure 19: SelecRng from vendor. .................................................................................................29
Figure 20: INSERTING values in Product table. .............................................................................31
Figure 21: SelecRng From product................................................................................................31
Figure 22: INSERTING into customer_order_product table. .........................................................32
Figure 23: SelecRng from customer_order_product. ...................................................................33
Figure 24: List of customer which are also the staff of the company. ..........................................34
Figure 25: List of order between the given dates. ........................................................................34
Figure 26 : LisRng all the orders. ...................................................................................................35
Figure 27: LisRng the product which second le]er is 'a and stock level is >50. ............................35
Figure 28: Customer who ordered recently. .................................................................................36
CC5051NI DATABASE

Figure 29: Total Revenue of each month. .....................................................................................37


Figure 30: The orders that are >= the average total amount. .......................................................37
Figure 31: Vendor who has supplied more than 3 products for the company..............................38
Figure 32: Customer who has ordered most in August. ...............................................................39
Figure 33: CreaRon of Dump file...................................................................................................42
Figure 34: Dump File.....................................................................................................................42
Figure 35: Command for Spool file. ..............................................................................................43
Figure 36: Showing SPOOL FILE. ...................................................................................................43
Figure 37: Dropping Table Customer. ...........................................................................................44
Figure 38: Dropping table order. ...................................................................................................44
Figure 39: Dropping table Invoice. ................................................................................................44
Figure 40; Dropping table Vendor. ................................................................................................44
Figure 41: Dropping table Product. ..............................................................................................44
Figure 42: Dropping table Customer_Orde_Productr...................................................................44
CC5051NI DATABASE

Table of tables.
Table 1: EnRRes and A]ributes .......................................................................................................6
Table 2: Customer Table ader NormalizaRon. ..............................................................................13
Table 3: Order table ader NormalizaRon ......................................................................................15
Table 4: Invoice table ader normalizaRon. ...................................................................................17
Table 5: Product table ader normalizaRon. ..................................................................................18
Table 6: Vendor table ader normalizaRon. ...................................................................................19
Table 7: Customer_Order_Product table ader normalizaRon. .....................................................21
CC5051NI DATABASE

1.Introduc4on
For this individual coursework, we are required to design a database system for a “Gadget
Emporium”. Especially we are required to make a database system which can keep all the tracks
of all customers, products and orders which will help to create a strong database system to
support a business.
We can save necessary informaRon in this database which will include all the informaRon of the
customers and orders. All the data are safe and can be used at any Rme without any problems
which is all because of database.
In this Individual Coursework, A case study is provided for use to analyse and create a database
system that meets all the requirement for that insRtute.

1.1 Aims and objec0ves of this Coursework.


• To design a normalize database system for a Gadget company,
• To store all data on database which will be easy to access,
• To give services to customers,
• To keep track of orders,
• To give best services to the customers.

1.2Tools used in this Coursework.


• Ms-Word
Þ Microsod provides Ms-Word, a tool for creaRng professional-quality documents, le]ers,
and other correspondence. Word processing sodware like Microsod Word includes
sophisRcated tools that let us edit and format our documents and files. In this Coursework
Ms-Word is used mainly to write report.
(Byjus.com, 2022)

Figure 1: Logo Of Ms-Word.

Prabin G.C. 1
CC5051NI DATABASE

• Draw.io
Þ A proprietary tool for creaRng charts and diagrams is called draw.io. With the sodware,
you can design a bespoke layout or select from an automaRc layout feature. To create a
unique diagram or chart, they offer a vast array of shapes and hundreds of visual features.
Making an eye-catching diagram or chart is made easy with the drag-and-drop feature.
(Computer Hope, 2024)

Figure 2:Logo of Draw.io.

• SQL PLUS by Oracle


Þ Oden used by programmers, administrators, and users, SQL Plus is the simplest basic
Oracle Database uRlity. It has a simple command-line interface. All the command are
wri]en in SQL plus and stored in database. In this Coursework SQL PLUS is used to store
all the informaRon in database.

Figure 3: Example of SQL PLUS.

Prabin G.C. 2
CC5051NI DATABASE

1.3 Current Business Ac0vi0es and Opera0ons.


Þ This Company provides fast and reliable services to the private customers within a short
Rme. Nowadays people usually prefer to receive their products as soon as possible, this
business provides customers with various faciliRes to make there deal fast and easy. In
this business all the data and informaRon of the customers are secured. This business’s
website can easily be accessed through any web plaoorms and customers can select the
Gadgets they want to purchase; a driver will track the locaRon the customers and drop
them to their desRnaRon.

1.4 Business Rule


“Gadget Emporium” is the business that will be in peak someday. It will be renowned
for its services and earning fame in Gadget marketing of Nepal. To maintain their success
in the Gadget marketing, they are following their own business rules. Some of the
business rules are listed below:
• Product Management System is implemented to handle the details of the products
and Gadgets,

• Customers are needed to provide actual information or their customer details,

• Customers are categorized as Regular(R), Staff(S) and VIP(V) also the rate of
discount is also categorized according to customers categorization,

• Order can be easily done through online,

• Recording system is also implemented to maintain the records of vendors and


suppliers,

• Order cannot be canceled after it’s already been processed,

• One customer can purchase more than one Gadget,

Prabin G.C. 3
CC5051NI DATABASE

• Each order detail must have one payment option,

• One vendor can supply one or more than one product,

• Invoice will include Destination, pickup location, Total price, and other information
about the Gadget.

1.5 Assump0ons
• The customers will be given a unique Customer_ID,
• One customer can order mulRple Rmes,
• Every single order has been assigned a unique Order_id.

2. En4ty Rela4onship Diagram


EnRty relaRonship diagrams are graphical or visual depicRons of the classificaRon and
relaRonship-building processes used to classify or idenRfy items of similar interest.
The components of ER diagram are:
• EnRty
• A]ributes
• RelaRonship

Prabin G.C. 4
CC5051NI DATABASE

2.1 A@ributes and En4ty


Considering this, the business rule defines the enRty and its a]ributes. Following
normalizaRon, these enRRes may have more members and are not confirmed.

Þ EnRRes: In an RDBMS, an enRty is a physical object that represents data. Consider a


university administraRon system, for instance. It keeps records of data regarding pupils,
instructors, classes, tests, etc. The tables in the database are the student, instructor,
course, and exam. An enRty in the student table is a record. It stands for a solitary student
item. A record in the lecturer table is an enRty in a similar way. It stands for a single
lecturer's object. We refer to these enRRes as powerful enRRes. (pedia, 2023)

Þ A]ributes: An enRty's properRes are called a]ributes. Let's take another look at the
university management system example. The properRes of the student enRty are name,
residence, age, GPA, and student ID. The course enRty contains a]ributes including dur,
course name, and course id. (pedia, 2023)

2.2 Crea4on of En44es and A@ributes


Þ There can be many enRRes in Online store of Gadgets. Some of the primary enRRes for
Gadget Emporium store are listed below:
• Customer
• Order

• Product

Prabin G.C. 5
CC5051NI DATABASE

Some of the En55es and A8ributes are given below:


EnRty A]ributes Foreign Key Primary Key

Customer Customer_ID(PK), Customer_ID(PK)


Customer_Name,
Customer_Address,
Customer_Number,
Customer_Category,
Discount_Rate
Order Order_ID(PK), Customer_ID(FK), Order_ID(PK) Customer_ID(FK)
Order_Date,QuanRty, Total
Amount, Invoice_ID, Invoice_Date
Payment_OpRon

Product Product_ID(PK), Product_Name, Vendor_ID(FK) Product_ID(PK)


Product_Category,
Unit_Price,Stock_Level
Vendor_ID,Vendor_Name
Vendor_Number

Table 1: En++es and A/ributes

Prabin G.C. 6
CC5051NI DATABASE

3. Ini4al ERD

Figure 4:Ini+al ERD

Prabin G.C. 7
CC5051NI DATABASE

4.Normaliza4on
NormalizaRon is the process of making the database more flexible by removing the varied
anomalies and data redundancies present in the database. NormalizaRon includes creaRng tables
and establishing relaRonships between those tables according to rules.

4.1 UNF (Un-Normalized Form)


Un-normalised form is a preparatory stage of the normalisaRon process allowing us to create
a structured frame, representaRve of a piece of organisaRonal data such as a form or document
(e.g invoice, report, purchase order etc.). This is our iniRal NormalisaRon ‘relaRon’ that contains
both real data, taken from the form or document, and modelled data, based upon and extended
from the original from or document. (Open Grass, 2023) The advantages of UNF are:
• UNF handles data structures.
• In UNF, Querying is simpler.
• Helps to organize the data.

Customer (Customer_ID(PK), Customer_Name, Customer_Address,


Customer_Number, Customer_Category, Discount_Rate{Order_ID(PK),
Order_Date, Quan@ty, Total_Amount, Invoice_ID, Invoice_Date, Payment_Op@on
{Product_ID(PK), Product_Name, Product_Category, Unit_Price, Stock_Level,
Vendor_ID, Vendor_Name, Vendor_Number}})

Prabin G.C. 8
CC5051NI DATABASE

4.2 1NF (First Normal Form)


A key idea in database architecture, First Normal Form (1NF) specifies the essenRal
framework for arranging data in relaRonal databases. EliminaRng redundant data and making
ensuring that it is kept consistently and logically are the two key objecRves of 1NF.
Guidelines in First Normal Form:
• There should only be single-valued characterisRcs and columns.
• A column’s values should correspond to the same domain.
• Each column name in a table needs to be unique.
• Moreover, the order in which the data are saved is not necessary. (Studytonight, 2023)

Customer1 (Customer_ID(PK), Customer_Name, Customer_Address,


Customer_Number, Customer_Category, Discount_Rate)

Order1 (Order_ID(PK), Customer_ID(FK), Order-Date, Quan@ty, Total_Amount,


Invoice_ID, Invoice-Date, Payment_Op@on)

Customer_order_product 1 (Product_ID(PK), Order_ID(FK), Customer_ID(FK),


Product_Name, Product_Category, Unit-Price, Stock_Level, Vendor_ID,
Vendor_Name, Vendor_Number)

In Summary these all (Customer1, Order1 and Customer-Order_Product1 ) are all


in 1NF and there are no repea@ng groups.

Prabin G.C. 9
CC5051NI DATABASE

4.3 2NF (Second Normal Form)


On the idea of fully funcRonal dependency, the second Normal Form (2NF) is built. For
relaRons with composite keys—that is, relaRons with a primary key made up of two or more
a]ributes—the second Normal Form is applicable. A relaRon is inherently in at least 2NF if its
primary key has only one a]ribute. The irregulariRes in updates could affect a relaRon that is not
in 2NF. A relaRon cannot be in the second normal form if it is not in the first normal form and
does not contain any parRal dependencies. If a relaRon does not depend on any suitable subset
of any candidate key in the table—that is, if no non-prime a]ribute—that is, if no a]ribute is part
of any candidate key—it is said to be in 2NF. (Geekforgeeks, 2023)
To be in Second Normal Form, a table must:
• It should be in 1NF.
• It shouldn’t be parRally dependent.

Showing Par,al Dependencies:


From Order1
Customer_ID + Order_ID ® Order_Date, QuanRty, Total_Amount, Invoice_ID, Invoice_Date,
Payment_OpRon

Customer_ID ® ´

Order_ID ® ´
From Customer_Order_Product 1
Customer_ID, Order_ID,Product_ID ® ´
Order_ID ® ´
Product_ID ® Product_Name, Product_Category, Unit_Price, Vendor_ID,
Vendor_Name, Vendor_Number, Stock_Level
Now, final table in 2NF:
Customer2 (Customer_ID(PK), Customer_Name, Customer_Address,
Customer_Number, Customer_Category, Discount_Rate)

Prabin G.C. 10
CC5051NI DATABASE

Order2(Order_ID(PK), Customer_ID(FK) Order_Date, Quan@ty, Total_Amount,


Invoice_ID, Invoice_Date, Payment_Op@on)
Customer Order Product 2 ( Customer_ID(FK), Order_ID(FK), Product_ID(FK))
Product 2 (Product_ID(PK), Product_Name, Product_Category, Unit_Price,
Vendor_ID, Vendor_Name, Vendor_Number, Stock_Level)

In summary, all these tables are in 2NF and is fully func@onally dependent on the
en@re primary key for each table.

4.4 3NF (Third Normal Form


If a relaRon is neither in the second normal form nor the third normal form due to a transiRve
dependency for non-prime a]ributes. When any non-trivial funcRon dependency X –> Y has at
least one of the following characterisRcs met, the relaRon is said to be in 3NF.
• X is an extraordinary key.
• Each element of Y is a component of a candidate key, making Y a prime characterisRc.

From Order 2
Order_ID® Invoice_ID® Invoice_Date ® Payment_Op@on

From Product 2
Product_ID ® Vendor_ID ® Vendor_Name ® Vendor_Number

Final 3NF
Customer 3 (Customer_ID(PK), Customer_Name, Customer_Address,
Customer_Number, Customer_Category, Discount_Rate)

Prabin G.C. 11
CC5051NI DATABASE

Order3 (Order_ID(PK), Invoice(FK), Customer_ID(FK) Order_Date, Quan@ty,


Total_Amount)
Invoice3 (Invoice_ID(PK), Invoice_Date, Payment_Op@on)
Customer Order Product 3 (Customer_ID(FK), Order_ID(FK), Product_ID(FK))
Product 3 (Product_ID(PK), Vendor_ID(FK), Product_Name, Product_Category,
Unit-price, Stock_Level)
Vendor3 (Vendor_ID(PK), Vendor_Name, Vendor_Name)

5. Final ERD

Figure 5: Final Normalised ERD.

Prabin G.C. 12
CC5051NI DATABASE

6. Data Implementa4on
The tables have been created by using ‘CREATE TABLE’ command. It is one of the most used
commands in MYSQL. To create a table using this command we need to provide a table name and
name of the columns that are going to be in the table. A table can have only one Primary Key and
a foreign key is a field in a table that refers to the primary Key in another table.

6.1 Crea0ng Tables


6.2 Customer
The table of customer aMer normaliza0on:
A]ributes Data type Constraints DescripRon
Customer_ID VARCHAR2(20) Primary Key, This stores the unique
Unique id of the customer.

Customer_Name VARCHAR2(20) NOT NULL This stores the name


of the customer.
Customer_Address VARCHAR2(20) NOT NULL This stores the
address of the
customer.
Customer_Number Number (20,2) NOT NULL This field stores the
number of the
customer.
Customer_Category VARCHAR2(20) NOT NULL This field stores the
category of the
customer i.e. Regular,
Staff and VIP
Discount_Rate Number (9,2) NOT NULL This field stores the
discount rate of the
customers.

Table 2: Customer Table aAer Normaliza+on.

Prabin G.C. 13
CC5051NI DATABASE

Command
Create table Customer (
Customer_ID VARCHAR2 (20) Primary key,
Customer_Name VARCHAR2 (20) NOT NULL,
Customer_Address VARCHAR2 (20) NOT NULL,
Customer_Number Number (20,2) NOT NULL,
Customer_Category VARCHAR2 (20) NOT NULL,
Discount_Rate Number(9,2) NOT NULL);

Figure 6: Crea+on of Customer table.

Prabin G.C. 14
CC5051NI DATABASE

6.3 Orders
The Orders table ader NormalizaRon:

A]ributes Data type Constraints DescripRon


Order_ID VARCHAR2(20) Primary Key This stores the order
id of the customer.
Invoice_ID VARCHAR2(20) Foreign Key, NOT This stores the
NULL Invoice_ID of the
customer.
Customer_ID VARCHAR2(20) Foreign Key, NOT This stores the
NULL Customer_ID of the
customer.
Order_Date Date NOT NULL This stores the order
date of the customer.
QuanRty INT NOT NULL This field stores the
quanRty of the
product.
Total_Amount Number(9,2) NOT NULL This field stores the
total amount of the
orders.

Table 3: Order table aAer Normaliza+on

Prabin G.C. 15
CC5051NI DATABASE

Command
CREATE TABLE Orders (
Order_ID VARCHAR2(20) PRIMARY KEY,
Invoice_ID VARCHAR2(20) NOT NULL REFERENCES Invoice(Invoice_ID),
Customer_ID VARCHAR2(20) NOT NULL REFERENCES Customer(Customer_ID),
Order_Date DATE NOT NULL,
QuanRty INT NOT NULL,
Total_Amount NUMBER(9,2) NOT NULL);

Figure 7:Crea+ng Order table.

Prabin G.C. 16
CC5051NI DATABASE

6.4 Invoice
A]ributes Data type Constraints DescripRon
Invoice_ID VARCHAR2(20) Primary Key This stores the
invoice id of the
customer.
Invoice_Date Date NOT NULL This stores the
invoice date of the
customer.
Payment_OpRon VARCHAR2(30) NOT NULL This field stores the
payment opRon.

Table 4: Invoice table aAer normaliza+on.

Command
CREATE TABLE Invoice (
Invoice_ID VARCHAR2(20) Primary key,
Invoice_Date Date NOT NULL,
Payment_OpRon VARCHAR2(30) NOT NULL);

Figure 8: Crea+ng Invoice table.

Prabin G.C. 17
CC5051NI DATABASE

6.5 Product
A]ributes Data type Constraints DescripRon
Product_ID VARCHAR2(20) Primary Key This stores the
product id of the
customer.
Vendor_ID VARCHAR2(20) Foreign Key, NOT This stores the
NULL Vendor_ID of the
customer.
Product_Name VARCHAR(255) NOT NULL This stores the name
of the product.
Product_Category VARCHAR(255) NOT NULL This field stores the
category of the
product.
Unit_Price Number(9,2) NOT NULL This field stores the
price of the products.
Stock_Level INT NOT NULL This field stores the
stock level of the
products.

Table 5: Product table aAer normaliza+on.

Command
CREATE TABLE Product (
Product_ID VARCHAR2(20) Primary Key,
Vendor_ID VARCHAR2(20) NOT NULL,
Product_Name VARCHAR(255) NOT NULL,
Product_Category VARCHAR(255) NOT NULL,
Unit_Price DECIMAL(10,2) NOT NULL,
Stock_Level INT NOT NULL,
FOREIGN KEY (Vendor_ID) REFERENCES Vendor(Vendor_ID));

Prabin G.C. 18
CC5051NI DATABASE

Figure 9: Crea+ng table Product.

6.6 Vendor
A]ributes Data type Constraints DescripRon
Vendor_ID VARCHAR2(20) Primary Key This stores the
vendor id.
Vendor_Name VARCHAR2(30) NOT NULL This stores the
vendor name.
Vendor_Number Number(20,2) NOT NULL This field stores the
vendor number.

Table 6: Vendor table aAer normaliza+on.

Command
CREATE TABLE Vendor (
Vendor_ID VARCHAR2(20) Primary Key,
Vendor_Name VARCHAR2(30) NOT NULL,
Vendor_Number Number(20,2) NOT NULL);

Prabin G.C. 19
CC5051NI DATABASE

Figure 10: Crea+ng table Vendor.

Prabin G.C. 20
CC5051NI DATABASE

6.7 Customer Order Product


A]ributes Data type Constraints
Customer_ID VARCHAR2(20) FOREIGN KEY, NUT NULL
Order_ID VARCHAR2(30) FOREIGN KEY, NOT NULL
Product_ID VARCHAR2(30) FOREIGN KEY, NOT NULL

Table 7: Customer_Order_Product table aAer normaliza+on.

Command
CREATE TABLE Customer_Order_Product(
Customer_ID VARCHAR(255) NOT NULL,
Order_ID VARCHAR(255)NOT NULL,
Product_ID VARCHAR(255) NOT NULL,
FOREIGN KEY (Customer_ID) REFERENCES Customer(Customer_ID),
FOREIGN KEY(Order_ID) REFERENCES Orders(Order_ID),
FOREIGN KEY(Product_ID) REFERENCES Product(Product_ID));

Figure 11: Crea+ng Customer_Order_Product table

Prabin G.C. 21
CC5051NI DATABASE

7. Popula4ng the Database tables.


7.1 INSERTING values into Customer table.
INSERT INTO Customer (Customer_id, Customer_Name, Customer_Address,
Customer_Number, Customer_Category, Discount_Rate) VALUES ('A1', 'Prawin',
'Kathmandu', '9867808034', 'Staff', '5');

INSERT INTO Customer (Customer_id, Customer_Name, Customer_Address,


Customer_Number, Customer_Category, Discount_Rate) VALUES ('A2', 'Alish', 'KriRpur',
'9847821172', 'Staff', '5');

INSERT INTO Customer (Customer_id, Customer_Name, Customer_Address,


Customer_Number, Customer_Category, Discount_Rate) VALUES ('A3', 'Roshan',
'Kalanki', '9809542910', 'VIP', '10');

INSERT INTO Customer (Customer_id, Customer_Name, Customer_Address,


Customer_Number, Customer_Category, Discount_Rate) VALUES ('A4', 'Utsav', 'Butwal',
'9867878034', 'VIP', '10');

INSERT INTO Customer (Customer_id, Customer_Name, Customer_Address,


Customer_Number, Customer_Category, Discount_Rate) VALUES ('A5', 'Murari',
'Chitwan', '9847870034', 'Regular', '0');

INSERT INTO Customer (Customer_id, Customer_Name, Customer_Address,


Customer_Number, Customer_Category, Discount_Rate) VALUES ('A6', 'Mubarak',
'NepalGunj', '9809879034', 'Regular', '0');

INSERT INTO Customer (Customer_id, Customer_Name, Customer_Address,


Customer_Number, Customer_Category, Discount_Rate) VALUES ('A7', 'Ishan’,
'Kathmandu’, '9809577034', 'Staff', '5');

Prabin G.C. 22
CC5051NI DATABASE

Figure 12: Inser+ng Values in Customer Table.

Figure 13: Selec+ng from Customer Table.

Prabin G.C. 23
CC5051NI DATABASE

7.2 INSERTING values into Invoice Table.


INSERT INTO Invoice (Invoice_ID, Invoice_Date, Payment_OpRon)
VALUES ('In1', to_date('01-Jan-2023', 'DD-Mon-YYYY'), 'COD, credit card, e-wallet');

INSERT INTO Invoice (Invoice_ID, Invoice_Date, Payment_OpRon)


VALUES ('In2', to_date('06-Jan-2023', 'DD-Mon-YYYY'), 'COD, credit card, e-wallet');

INSERT INTO Invoice (Invoice_ID, Invoice_Date, Payment_OpRon)


VALUES ('In3', to_date('09-Jan-2023', 'DD-Mon-YYYY'), 'COD, credit card, e-wallet');

INSERT INTO Invoice (Invoice_ID, Invoice_Date, Payment_OpRon)


VALUES ('In4', to_date('25-Jan-2023', 'DD-Mon-YYYY'), 'COD, credit card, e-wallet');

INSERT INTO Invoice (Invoice_ID, Invoice_Date, Payment_OpRon)


VALUES ('In5', to_date('15-feb-2023', 'DD-Mon-YYYY'), 'COD, credit card, e-wallet');

INSERT INTO Invoice (Invoice_ID, Invoice_Date, Payment_OpRon)


VALUES ('In6', to_date('28-feb-2023', 'DD-Mon-YYYY'), 'COD, credit card, e-wallet');

INSERT INTO Invoice (Invoice_ID, Invoice_Date, Payment_OpRon)


VALUES ('In7', to_date('05-Mar-2023', 'DD-Mon-YYYY'), 'COD, credit card, e-wallet');

Prabin G.C. 24
CC5051NI DATABASE

Figure 14: Inser+ng Values in Invoice Table.

Figure 15: Selec+ng from Invoice.

Prabin G.C. 25
CC5051NI DATABASE

7.3 INSERTING values in Orders Table


INSERT INTO Orders (Order_ID, Invoice_ID, Customer_ID,Order_Date, QuanRty,
Total_Amount)
VALUES ('O1', 'In1', 'A1',to_date ('01-Jan-2023', 'DD-Mon-YYYY'), 10, 50000.00);

INSERT INTO Orders (Order_ID, Invoice_ID, Customer_ID, Order_Date, QuanRty,


Total_Amount)
VALUES ('O2', 'In2', 'A2', to_date ('07-Jan-2023', 'DD-Mon-YYYY'), 5, 25000.00);

INSERT INTO Orders (Order_ID, Invoice_ID, Customer_ID ,Order_Date, QuanRty,


Total_Amount)
VALUES ('O3', 'In3', 'A3',to_date ('13-Jan-2023', 'DD-Mon-YYYY'), 7, 33000.00);

INSERT INTO Orders (Order_ID, Invoice_ID, Customer_ID ,Order_Date, QuanRty,


Total_Amount)
VALUES ('O4', 'In4', 'A4', to_date ('22-Jan-2023', 'DD-Mon-YYYY'), 11, 30000.00);

INSERT INTO Orders (Order_ID, Invoice_ID, Customer_ID ,Order_Date, QuanRty,


Total_Amount)
VALUES ('O5', 'In5', 'A5', to_date ('12-feb-2023', 'DD-Mon-YYYY'), 3, 3000.00);

INSERT INTO Orders (Order_ID, Invoice_ID, Customer_ID ,Order_Date, QuanRty,


Total_Amount)
VALUES ('O6', 'In6’, 'A6',to_date ('25-feb-2023', 'DD-Mon-YYYY'), 6, 21000.00);

INSERT INTO Orders (Order_ID, Invoice_ID, Customer_ID ,Order_Date, QuanRty,


Total_Amount)
VALUES ('O7', 'In7', 'A7', to_date ('1-Mar-2023', 'DD-Mon-YYYY'), 4, 4000.00);

Prabin G.C. 26
CC5051NI DATABASE

Figure 16:Inser+ng Values in Orders table.

Figure 17:Selec+ng From Order table.

Prabin G.C. 27
CC5051NI DATABASE

7.4 INSERTING into Vendor table.


INSERT INTO Vendor (Vendor_ID, Vendor_Name, Vendor_Number)
VALUES ('V1', 'Electronics HUB', 9845608034);

INSERT INTO Vendor (Vendor_ID, Vendor_Name, Vendor_Number)


VALUES ('V2', 'Prawin Electronics', 9847821175);

INSERT INTO Vendor (Vendor_ID, Vendor_Name, Vendor_Number)


VALUES ('V3', 'Gadget Pasal', 9809820108);

INSERT INTO Vendor (Vendor_ID, Vendor_Name, Vendor_Number)


VALUES ('V4', 'Innovate tech', 9809821179);

INSERT INTO Vendor (Vendor_ID, Vendor_Name, Vendor_Number)


VALUES ('V5', 'ING HUB', 9847900599);

INSERT INTO Vendor (Vendor_ID, Vendor_Name, Vendor_Number)


VALUES ('V6', 'Gaming Zone', 9809588830);

INSERT INTO Vendor (Vendor_ID, Vendor_Name, Vendor_Number)


VALUES ('V7', 'Hamro Electronics', 9809520107);

Prabin G.C. 28
CC5051NI DATABASE

Figure 18: INSERTING into Vendor table.

Figure 19: Selec+ng from vendor.

Prabin G.C. 29
CC5051NI DATABASE

7.5 INSERTING values in Product Table.


INSERT INTO Product (Product_ID, Vendor_ID, Product_Name, Product_Category,
Unit_Price, Stock_Level) VALUES ('P1', 'V1', 'Projector', 'Electronics', 5000.00, 10);

INSERT INTO Product (Product_ID, Vendor_ID, Product_Name, Product_Category,


Unit_Price, Stock_Level) VALUES ('P2', 'V2', 'Keyboard', 'Electronics', 1500.00, 20);

INSERT INTO Product (Product_ID, Vendor_ID, Product_Name, Product_Category,


Unit_Price, Stock_Level) VALUES ('P3', 'V2', 'Headphone', 'Electronics', 1000.00, 55);

INSERT INTO Product (Product_ID, Vendor_ID, Product_Name, Product_Category,


Unit_Price, Stock_Level) VALUES ('P4', 'V2', 'JoysRck', 'Electronics', 3500.00, 40);

INSERT INTO Product (Product_ID, Vendor_ID, Product_Name, Product_Category,


Unit_Price, Stock_Level) VALUES ('P5', 'V2', 'Monitor', 'Electronics', 15000.00, 7);

INSERT INTO Product (Product_ID, Vendor_ID, Product_Name, Product_Category,


Unit_Price, Stock_Level) VALUES ('P6', 'V5', 'Pendrive', 'Electronics', 500.00, 30);

INSERT INTO Product (Product_ID, Vendor_ID, Product_Name, Product_Category,


Unit_Price, Stock_Level) VALUES ('P7', 'V7', 'Harddisk', 'Electronics', 2500.00, 47);

Prabin G.C. 30
CC5051NI DATABASE

Figure 20: INSERTING values in Product table.

Figure 21: Selec+ng From product.

Prabin G.C. 31
CC5051NI DATABASE

7.6 INSERTING values in Customer_Order_Product Table


INSERT INTO Customer_Order_Product (Customer_ID, Order_ID, Product_ID)
VALUES ('A1', 'O1', 'P1');
INSERT INTO Customer_Order_Product (Customer_ID, Order_ID, Product_ID)
VALUES ('A2', 'O2', 'P5');
INSERT INTO Customer_Order_Product (Customer_ID, Order_ID, Product_ID)
VALUES ('A1', 'O1', 'P7');
INSERT INTO Customer_Order_Product (Customer_ID, Order_ID, Product_ID)
VALUES ('A3', 'O3', 'P3');
INSERT INTO Customer_Order_Product (Customer_ID, Order_ID, Product_ID)
VALUES ('A4', 'O4', 'P4');
INSERT INTO Customer_Order_Product (Customer_ID, Order_ID, Product_ID)
VALUES ('A5', 'O5', 'P4');
INSERT INTO Customer_Order_Product (Customer_ID, Order_ID, Product_ID)
VALUES ('A7', 'O7', 'P7');

Figure 22: INSERTING into customer_order_product table.

Prabin G.C. 32
CC5051NI DATABASE

Figure 23: Selec+ng from customer_order_product.

Prabin G.C. 33
CC5051NI DATABASE

8. Database Querying
8.1 Informa0on Query
8.1.1 List all the customers that are also staff of the company.
Command
SELECT *FROM Customer
WHERE Customer_Category = 'Staff';

Figure 24: List of customer which are also the staff of the company.

8.1.2 List all the orders made for any product between the dates 01-05-2023 Fll 28-05-2023.
Command
SELECT *
FROM Orders
WHERE Order_Date Between TO_DATE ('01-Jan-2023', 'DD-Mon-YYYY') AND
TO_DATE('28'-Jan-2023', 'DD-Mon-YYYY');

Figure 25: List of order between the given dates.

Prabin G.C. 34
CC5051NI DATABASE

8.1.3 List all the customers with their order details and the customers who haven’t ordered any
products yet.
Command
SELECT
C.Customer_ID, C.Customer_Name, O.Order_ID,O.Order_Date,O.Total_Amount,
O.Invoice_ID
FROM Customer C LEFT JOIN Orders O
ON C.Customer_ID = O.Customer_ID;

Figure 26 : Lis+ng all the orders.

8.1.4 List all product details that have the second leIer ‘a’ in their product name and have stock
quanFty more than 50.
Command
SELECT *FROM Product
WHERE Product_name LIKE '_a%' AND Stock_Level > 50;

Figure 27: Lis+ng the product which second le/er is 'a and stock level is >50.

Prabin G.C. 35
CC5051NI DATABASE

8.1.5 Find out the customer who has ordered recently. DHFibernet@0414435
Command
SELECT Order_ID as Order_ID, customer_name
FROM Orders
JOIN customer ON Orders.customer_id = customer.customer_id
ORDER BY Order_date DESC
FETCH FIRST 1 ROWS ONLY;

Figure 28: Customer who ordered recently.

Prabin G.C. 36
CC5051NI DATABASE

8.2 Transac0on Query


8.2.1 Show the total revenue of the company for each month.
Command
SELECT
TO_CHAR(Order_date, 'MM-YYYY') AS month,
SUM(Total_Amount) AS Total_Revenue
FROM Orders
GROUP BY TO_CHAR(Order_date, 'MM-YYYY')
ORDER BY month;

Figure 29: Total Revenue of each month.

8.2.2 Find those orders that are equal or higher than the average order total value.
Command
SELECT *
FROM orders
WHERE Total_Amount >= (SELECT AVG(Total_amount) FROM orders);

Figure 30: The orders that are >= the average total amount.

Prabin G.C. 37
CC5051NI DATABASE

8.2.3 List the details of vendors who have supplied more than 3 products to the company.
Command
SELECT Vendor_id, Vendor_name
FROM Vendor
WHERE Vendor_ID IN (SELECT Vendor_id
FROM Product
GROUP BY Vendor_id HAVING COUNT(*) > 3);

Figure 31: Vendor who has supplied more than 3 products for the company.

Prabin G.C. 38
CC5051NI DATABASE

8.2.5 Find out the customer who has ordered the most in August with his/her total spending on
that month.
Command
SELECT*FROM (SELECT C.Customer_ID, C.Customer_Name,
SUM(O.Total_Amount) AS Spending_in_August FROM Customer C
JOIN Orders O ON C.Customer_ID = O.Customer_ID
WHERE TO_CHAR (O.Order_Date, 'MM-YYYY')= '08-2023'
GROUP BY C.Customer_ID, C.Customer_Name
ORDER BY Spending_in_August DESC)
WHERE ROWNUM = 1;

Figure 32: Customer who has ordered most in August.

Prabin G.C. 39
CC5051NI DATABASE

9. Cri4cal Evalua4on
9.1 Further Discussion on your learning Experience.

At First, I did not have the knowledge about database but ader studying in this semester, I
have been able to design, develop and acquire knowledge about database and its design.
In this Semester, I have gained informaRon about how really the process of database runs and I
learned about different new topics like database querying and creaRng ERD.
NormalizaRon and ERD are the main topic to learn in this module in this semester. ERD is the
graphical representaRon of relaRonships of enRRes and their a]ributes. NormalizaRon is the
process in database system that helps to avoid the data redundancy. In this project I have done
normalizaRon in four steps UNF, 1NF, 2NF and 3NF. It also helped to learn SQL commands and
how to run SQL PLUS.
In the beginning, I was so much confused about where to start from and I didn’t have much
idea about database, due to this I had to face many problems while doing the coursework. That
made me to search a lot about database and its commands which really help me to gain more
knowledge and helped in doing coursework. I had problems while selecRng enRRes and in
normalizaRon. I carried various research to carry out this coursework. This coursework helped me
to understand more about database which will surely help me in my future.

Prabin G.C. 40
CC5051NI DATABASE

9.2 Cri0cal Evalua0on


An organized collecRon of structured data, frequently stored electronically in a computer
system, is called a database. We can keep all our data in databases and retrieve it anyRme we
need to. Databases are a common tool used by businesses to store all their data and safeguard it
in the case of a system breakdown. InformaRon that will help the company and boost profitability
is what this module aims to store. A large amount of data can be used in databases, and it can be
located easily and fast.
We can also change the info that has been added. It lets users to have varying levels of privilege.
For instance, some users might be able to read data but not write it. Databases and many other
subjects are related, such as cloud compuRng.
Cloud compuRng offers a wide range of services, such as sodware, databases, storage, and much
more. Another name for the cloud is the internet. All necessary informaRon is accessible online.
Services on the cloud have been provided by the database. Cloud compuRng also allows for the
creaRon of databases that are internet-enabled and accessible from any locaRon. Although
everybody can view the data in the database, not everyone is able to update it. AddiRonally, it is
related to sodware engineering. A database is necessary to maintain the variety of data that
comes with any sodware package. Because ERD, normalizaRon, and query are all linked to
databases, they all need to be comprehended precisely within the framework of sodware
engineering. Every industry must store data. Because of this, databases are employed these days
to handle data. Data entered by users is oden unstructured, but a database maintains its
structure. The outcomes are presented in an organized manner.
Our curriculum involved creaRng a database for a company that operates transportaRon.
Customer, driver, service, invoice, and a plethora of other data kinds are required by this firm.
Customers' names, email addresses, and contact details are accessible to both drivers and stores.
In this industry, there are some rules that need to be followed. The data that has been stored is
all safe and secure. The data is safe even if the system malfuncRons and is easily accessible from
any locaRon.

Prabin G.C. 41
CC5051NI DATABASE

10.Droping table and dump file crea4on


10.1 Crea0on of Dump File

Figure 33: Crea+on of Dump file.

Figure 34: Dump File.

Prabin G.C. 42
CC5051NI DATABASE

10.2 Crea0ng Spool file.

Figure 35: Command for Spool file.

Figure 36: Showing SPOOL FILE.

Prabin G.C. 43
CC5051NI DATABASE

10.3 Dropping tables.

Figure 37: Dropping Table Customer.

Figure 38: Dropping table order.

Figure 39: Dropping table Invoice.

Figure 40; Dropping table Vendor.

Figure 41: Dropping table Product.

Figure 42: Dropping table Customer_Orde_Productr

Prabin G.C. 44
CC5051NI DATABASE

11.References
Byju's. (2022). From h]ps://byjus.com/govt-exams/microsod-
word/#:~:text=Used%20to%20make%20professional%2Dquality,in%20the%20best%20possible
%20way.
(2022). From Byjus.com: h]ps://byjus.com
(2019). From Tella: h]ps://www.tella.tv
(2024). From Computer Hope: h]ps://www.computerhope.com
Open Grass. (2023). From Open Grass: h]p://rdbms.opengrass.net/
pedia. (2023). From pedia: h]ps://pediaa.com/
Studytonight. (2023). From studytonight: h]ps://www.studytonight.com/
Geekforgeeks. (2023). From Geek For Geeks: h]ps://quillbot.com/

Prabin G.C. 45

You might also like