You are on page 1of 29

Database Design & Development (GCD0821)

Project name: ElectroShop’s Database System

Author: Huynh Thai Hieu-GCD18314

Technical Design Document


Issue 1
Technical Design Document Page ii

IDA-MS-TD
Issue 1

TABLE OF CONTENTS

1 INTRODUCTION ........................................................................................................1
1.1 Purpose ....................................................................................................................1
1.2 Scope ........................................................................................................................1
1.3 Definitions, Acronyms and Abbreviations ...........................................................1
1.4 References ...............................................................................................................2
1.5 Overview .................................................................................................................2
2 SYSTEM DESIGN .......................................................................................................3
2.1 System Context .......................................................................................................3
2.2 System Characteristics ...........................................................................................4
2.3 System Architecture ...............................................................................................4
2.4 Infrastructure Services ..........................................................................................7
2.5 Design Method and Standards ..............................................................................7
2.6 Programming Standards .....................................................................................10
2.7 Database diagram.................................................................................................12
2.8 Program evidences ...............................................................................................13

3. SOFTWARE QUERIES (EVIDENCES)................................................................ 19


3.1 Insert Queries ...................................................................................................... 19
3.2 View Queries ............................................................................................................. 23
3.3 Select Queries............................................................................................................ 24
Technical Design Document Page 1

IDA-MS-TD
Issue 1

1 INTRODUCTION

ElectroShop is a store who acquire and sell electronic devices to customers


throughout Viet Nam. This document will provide a detailed and professional
information about the ElectroShop’s Database System by using SQL Server

1.1 PURPOSE

a. Using SQL Server Management System to develop a Relational Database System


for ElectroShop in order to provide them a system that can fulfil their purpose of
storing information, replacing their current Flat Database System which is being
out-of-date.
b. Provide a clear and detailed report that every user could easily understand.

1.2 SCOPE

a. Develop a Relational Database System to store and protect the data of a store
b. This system will store the store’s necessary data, which are:
• Customer Information
• Seller (Employee) Information
• Product & Provider Information
• Invoice Information

c. Designed by using Relational Database and 3NF Normalization Process, this


System will provide a fully functional Database which includes:
• Data validations
• Data normalization
• Data interfaces for different situations
• Data modification
• Calculate Seller’s (Employee) bonus

1.3 DEFINITIONS, ACRONYMS AND ABBREVIATIONS

a) Acronyms & Definitions:


• ERD: Entity Relationship Diagram
• PK:Primary Key
Technical Design Document Page 2

IDA-MS-TD
Issue 1

• FK:Foreign Key
b) Abbreviations:

1.4 REFERENCES

1.5 OVERVIEW

/1 This project was made in order to develop a Relational Database based on Microsoft
SQL Server. Acknowledged by using information from … (reference documents).
/2 This Database consists of 6 Entities and 25 Attributes in total.
/3 System context:
ElectroShop is a store who have been using Flat File Database to save all of their data,
acknowledging the shortness of this method, this Relational Database system will be a
better method to store their data.
/4 System design method:
• Using Arrow.io Application to draw the detailed Logical Design of
ElectroShop’s Database
• Develop the Physical Design and also functioned on Microsoft SQL Server
Management Studio 17.
Technical Design Document Page 3

IDA-MS-TD
Issue 1

2 SYSTEM DESIGN

2.1 SYSTEM CONTEXT

ElectroShop is an electronic store who have been using Notebooks (Flat


File Database) to store:
• Customer Information
• Seller (Employee) Information
• Product & Provider Information
• Invoice Information

In the beginning, ElectroShop has a small database system and is limited to


paper-work by getting information from this Invoice:
Technical Design Document Page 4

IDA-MS-TD
Issue 1

Every Invoice has two copies, one will be given to the customer when they finish
purchasing, one will get stored by tagged in the store’s bills-notebook. Customer
Information that included in each Invoice will be stored in a different notebook-
Customer Information. They also have another notebook to store information about
the products that they have and information of their suppliers. To store information
of their Sellers, they also have a notebook for it.
But, after an amount of time, amount of information about customers and products
became too much to handle, the system needs to be expanded. If they keep using
the Notebook method, they will find it hard to control their database such as harder
to find, to make changes on the information, ...

2.2 SYSTEM CHARACTERISTICS

This Relational Database System will be able to:


• Operate in real-time to add new data about Customer’s information.
• Manage and control the product’s information in the most efficiency way.
• Calculate Seller’s bonus each month based on the amount of sales they
have made.
• Create comparative reports

2.3 SYSTEM ARCHITECTURE

a) Normalization Process:
Acknowledged ElectroShop’s requirements by information that they give, this
system will be designed with 6 Entities and 25 Attributes in total. But to get to
that, information needs to get through the Normalization process bellow in order
to get rid of repeating or anomaly data:
Technical Design Document Page 5

IDA-MS-TD
Issue 1

Unnormalized 1NF Normalization 2NF Normalization 3NF Normalization


attributes
Bill ID Bill ID Bill ID Bill ID
Seller ID Seller ID Seller ID Seller ID
Seller’s name Seller’s name Seller’s name Customer ID
Seller’s Date of Birth Seller’s Date of Birth Seller’s Date of Birth Date of bill
Seller’s gender Seller’s gender Seller’s gender
Seller’s address Seller’s address Seller’s address Seller ID
Seller’s phone Seller’s phone Seller’s phone Seller’s name
Customer ID Customer ID Customer ID Seller’s Date of Birth
Customer’s name Customer’s name Customer’s name Seller’s gender
Customer’s address Customer’s address Customer’s address Seller’s address
Customer’s phone Customer’s phone Customer’s phone Seller’s phone
Customer’s gender Customer’s gender Customer’s gender
Customer’s E-mail Customer’s E-mail Customer’s E-mail Customer ID
Date of bill Date of bill Date of bill Customer’s name
Product ID Customer’s address
Product Name Bill ID Bill ID Customer’s phone
Price Product ID Product ID Customer’s gender
Calculation unit Product Name Sold Quantity Customer’s E-mail
In stock quantity Price Selling price
Supplier ID Calculation Unit Bill ID
Supplier Name In stock quantity Product ID Product ID
Supplier Address Supplier ID Product Name Sold Quantity
Supplier Phone Supplier Name Price Selling price
Sold Quantity Supplier Address Calculation unit
Selling price Supplier Phone In stock quantity Product ID
Sold Quantity Supplier ID Product Name
Selling price Supplier Name Price
Supplier Address Calculation unit
Supplier Phone Supplier ID
In stock quantity

Supplier ID
Supplier Name
Supplier Address
Supplier Phone

b) Logical Entity Relationship Diagram (ERD):


After finishing the Normalization process, this following Logical Entity
Relationship Diagram (ERD) will represents the relationships between
Entities that consist in this system:
Technical Design Document Page 6

IDA-MS-TD
Issue 1

Diagram 1. Logical ERD for ElectroShop’s Database


Diagram 1 shown an over-all information of 6 Entities that will consist in this
Database System. Every each of them has a decent related to another, in details:
• As in Customer_Information Entity, which consist of 7 Attributes
(CustomerID, Customer_Name, Customer_Date_of_Birth,
Customer_Address, Customer_Phone, Customer_Gender and
Customer_Email), having CustomerID as a Primary Key and will join
in Bill_Information Entity as a Foreign Key.
• As in Seller_Information Entity, which consist of 6 Attributes
(SellerID, Seller_Name, Seller_Date_of_Birth, Seller_Gender,
Seller_Address and Seller_Phone), having SellerID as a Primary Key
and also will join in Bill_Information Entity as a Foreign Key.
• As in Bill_Information Entity, which consist of 4 Attributes (BillID,
SellerID, CustomerID and Date_of_Bill), having BillID as a Primary
Key and having SellerID and CustomerID as Foreign Keys.
• As in Bill_Details Entity, which consist of 4 Attributes (BillID,
ProductID, Sold_Quantity, Selling_Price) having both BillID and
ProductID as Primary Keys and also as Foreign Key which referenced
from Bill_Information Entity and Product_Information Entity.
Technical Design Document Page 7

IDA-MS-TD
Issue 1

• As in Product_Information Entity, which consist of 6 Attributes


(ProductID, SupplierID, Product_Name, Price, Calculation_Unit and
In_Stock_Quantity), having ProductID as Primary Key that will join
Bill_Details Entity as a Foreign Key. This Entity also have SupplierID
as a Foreign Key that referenced from Supplier_Information Entity.
• As in Supplier_Information Entity, which consist of 4 Attributes
(SupplierID, Supplier_Name, Supplier_Address and Supplier_Phone),
having SupplierID as Primary Key that will join
Product_Information Entity as a Foreign Key.
To sum up, 25 Attributes after 3NF Normalization Process now will be divided
into 6 Entities that all have related to each other in different ways. Thanks to
3NF Process, the architecture of this Database System became more efficient and
clearer, as well as coinsurance about avoiding repeating data or anomaly data.

2.4 INFRASTRUCTURE SERVICES

By dividing the data-sources into different parts (tables), this System will provide:
• Data filter: Input data will be filtered to avoid data redundancy before
being able to join the Database. For Example, information of one
Customer will never be able to be added into the Database multiple times.
• Data Modification: Out-of-date data or wrong data could be modified easily
(For authorized person only). In such cases, if the data is changed at one
place, the change has to be duplicated in each of the files where it’s related
to or referenced from.
• Security: Features like multiple views offer security to some extent
where users are unable to access data of other users and departments.

2.5 DESIGN METHOD AND STANDARDS

This Database system will consist of 6 Tables, which are:


• Customer_Information table:
This table is used to store all information about ElectroShop’s customers. It
has 7 columns such as: CustomerID, Customer_name, Date_of_Birth,
Customer_address, Customer_phone, Customer_gender and
Customer_Email. Among these, CustomerID is the Primary key.
Those columns such as: CustomerID, Customer_name, Date_of_Birth,
Customer_address, Customer_phone, Customer_gender are not allowed to be
null, especially, Customer_gender must be “Male” or “Female”. In details,
this table can be shown as follow:
Technical Design Document Page 8

IDA-MS-TD
Issue 1

Column name Data Type Allow Constraint


null
CustomerID nvarchar(10) no PK
Customer_name nvarchar(100) no
Date_of_Birth Date no
Customer_address nvarchar(500) no
Customer_gender nvarchar(10) no Check(Customer_gender=’male’
OR Customer_gender=‘female’)
Customer_phone Int yes Unique
Customer_Email nvarchar(100) yes

• Seller_Information table:
This table is used to store all information about ElectroShop’s seller. It has 6
columns such as: SellerID, Seller_Name, Seller_Date_of_Birth,
Seller_Gender, Seller_Address and Seller_Phone. Among these, SellerID is
the Primary key.
Every column in this table are not allowed to be null. Seller_Gender must
be checked between “male” or “female”. In details, this table can be shown
as follow:
Column name Data Type Allow Constraint
null
SellerID nvarchar(10) no PK
Seller_Name nvarchar(100) no
Seller_Date_of_Birth Date no
Seller_Gender nvarchar(10) no Check(Seller_Gender=’male’
OR Seller_Gender=‘female’)
Seller_Address nvarchar(500) no
Seller_Phone Int no Unique

• Bill_Information table:
This table is used to store the main basic information of ElectroShop’s invoice. It
has 4 columns such as: BillID, SellerID, CustomerID and Date_of_bill. Among
these, BillID is the Primary key. This table also having SellerID and CustomerID
as Foreign keys, which referenced from Seller_Information table and
Customer_Information table. In details, this table can be shown as follow:
Technical Design Document Page 9

IDA-MS-TD
Issue 1

Column name Data Type Allow null Constraint


BillID nvarchar(10) no PK
SellerID nvarchar(10) no FK
CustomerID nvarchar(10) no FK
Date_of_bill datetime yes Default(getdate())

• Bill_Details table:
This table is used to store detailed information of ElectroShop’s invoice. It has 4
columns such as: BillID, ProductID, Sold_Quantity, Selling_Price. Among these,
BillID and ProductID are Primary Keys, at the same time, they are also Foreign
Keys referenced from Bill_Information table and Product_Information table.
Except of Bonus_for_Seller is available for null, every other column will not be
allowed for any null. Sold_Quantity and Selling_Price needs to check to make
sure it’s larger than zero (>0). In details, this table can be shown as follow:

Column name Data Type Allow Constraint


null
BillID nvarchar(10) no PK, FK1
ProductID nvarchar(10) no PK, FK2
Sold_Quantity smallint no Check (SoldQuantity>0)
Selling_Price money no Check(Selling_Price>0)

• Product_Information table:
This table is used to store detailed information of ElectroShop’s product. It has 6
columns such as: ProductID, SupplierID, Product_Name, Calculation_Unit, Price
and In_Stock_Quantity. Among these, ProductID is the Primary Key and
SupplierID as Foreign Key which referenced from Supplier_Information table.
In_Stock_Quantity must be larger or at least equals 0. Product_Name and Price
are not being able for null and Calculation_Unit has a default as “pc(s)”. Price are
not able to smaller than 0. In details, this table can be shown as follow:

Column name Data Type Allow Constraint


null
ProductID nvarchar(10) no PK
SupplierID nvarchar(10) no FK
Product_Name nvarchar(100) no Unique
Technical Design Document Page 10

IDA-MS-TD
Issue 1

Calculation_Unit nvarchar(50) yes Default(‘pc(s)’)


Price money no Check(Price>0)
In_Stock_Quantity Int no Check(In_Stock_Quantity>=0)

• Supplier_Information table:
This table is used to store information of ElectroShop’s supplier. It has 4
columns such as: SupplierID, Supplier_name, Supplier_address and
Supplier_phone. Among these, SupplierID is the Primary Key. Supplier_name
and Supplier_address are not allowed to be null, also, Supplier_phone have to be
unique. In details, this table can be shown as follow:

Column name Data Type Allow null Constraint


SupplierID nvarchar(10) no PK
Supplier_name nvarchar(100) no
Supplier_address nvarchar(500) no
Supplier_phone int no unique

2.6 PROGRAMMING STANDARDS

This section will contain detailed instructions for the Database completion by
declaring the Query codes made with Microsoft SQL Server Management Studio.
In details:
First up, the Database must be created:
create database ElectroShop_Database;
After finishing the Database creation step, tables and its entities (columns) must
be created, which are:
• Supplier_Information table:

create table Supplier_Information( SupplierID


nvarchar(10) Primary key, Supplier_name
nvarchar(100) not null, Supplier_address
nvarchar(500) not null,

Supplier_phone int unique not null);

• Customer_Information table:
Technical Design Document Page 11

IDA-MS-TD
Issue 1

create table Customer_Information(


CustomerID nvarchar(10) Primary key,
Customer_name nvarchar(100) not null,
Date_of_Birth date not null,
Customer_address nvarchar(500) not null,
Customer_Gender nvarchar(10)
check(Customer_Gender='male' OR
Customer_Gender='female') not null,
Customer_phone int unique,
Customer_Email nvarchar(100));

• Seller_Information table:

create table Seller_Information( SellerID


nvarchar(10) Primary key, Seller_Name
nvarchar(100) not null,
Seller_Date_of_Birth date not null,
Seller_Gender nvarchar(10)
check(Seller_Gender='male' or
Seller_gender='female') not null,
Seller_Address nvarchar(500) not null,
Seller_Phone int not null unique);

• Bill_Information table:
create table Bill_Information(
BillID nvarchar(10) Primary key,
SellerID nvarchar(10) Foreign key references
Seller_Information(SellerID) on update cascade
on delete cascade not null,
CustomerID nvarchar(10) Foreign key references
Customer_Information(CustomerID) on update
cascade on delete cascade not null,
Date_of_bill datetime default(getdate()));
• Product_Information table:

create table Product_Information(


ProductID nvarchar(10) Primary key,
SupplierID nvarchar(10) foreign key references
Supplier_Information(SupplierID) on update cascade
on delete cascade not null,
Product_Name nvarchar(100) not null unique,
Technical Design Document Page 12

IDA-MS-TD
Issue 1

Calculation_Unit nvarchar(50)
default('pc(s)'),
Price money not null check(Price>0),
In_Stock_Quantity int check(In_Stock_Quantity>=0)
not null);
• Bill_Details table:

create table Bill_Details(


BillID nvarchar(10) Foreign key references
Bill_Information(BillID) on update cascade on
delete cascade not null,
ProductID nvarchar(10) Foreign key references
Product_Information(ProductID) on update cascade on
delete cascade not null,
Sold_Quantity smallint check(Sold_Quantity>0) not
null,
Selling_Price money not null check(Selling_Price>0),
Constraint PKBP Primary key (BillID, ProductID));

2.7 DATABASE DIAGRAM

After executing the Query, this following Diagram will represent an


overview of the Database and how tables connect to each other:
Technical Design Document Page 13

IDA-MS-TD
Issue 1

2.8 PROGRAM EVIDENCES

a) Database with sample data:


• Customer_Information table:

• Seller_Information table:

• Bill_Information table:

• Bill_Details table:
Technical Design Document Page 14

IDA-MS-TD
Issue 1

• Product_Information table:

• Supplier_Information table:
Technical Design Document Page 15

IDA-MS-TD
Issue 1

b) Database views:
• This view is to declare detailed information of each bill which include BillID,
name of the product with its selling price, calculation unit, amount of device
that got sold and total price (by multiplying Sold_Quantity and Selling_Price):

View 1. Invoice view.


• This view is to declare an overall information about each bill by
including BillID, Seller name, customer name and total of bill:

View 2. Bill’s information view


• In order to achieve one of the requirements from ElectroShop, this view
was made to declare information in order to count Seller’s bonus for each
month based on bills that they made.

View 3. Bonus for Seller (by each bill) in February 2018


In this following example, in February 2018, 4 bills have been
made by 2 Sellers, this view will show SellerID, Seller name,
BillID that they sold, total amount of each bill and how much
money they got from each (counted by 2% of each bill).
Technical Design Document Page 16

IDA-MS-TD
Issue 1

o In order to sum-up the bonus, this view will provide total


bonus for each seller in a current month. For instance,
following up picture is this view displaying total bonus
for seller in February 2018:

View 4. Bonus for Seller (in total) in February 2018


• In order to accomplish another requirement from ElectroShop, this view was
made to display information about all of the products that they have so that
they can inform to their customer through Email:

This view display detailed name of each product, current in-


stock quantity and its price which accounted by its original price
with 10% VAT addition.
c) Modification on Tables:
• Update Product’s in-stock quantity information, now, every product’s
quantity will be 10:
Technical Design Document Page 17

IDA-MS-TD
Issue 1

by using following Queries:

Update Product_Information set In_Stock_Quantity=10


where ProductID='CAP01';
Update Product_Information set In_Stock_Quantity=10
where ProductID='DEL01';
Update Product_Information set In_Stock_Quantity=10
where ProductID='HPL01';
Update Product_Information set In_Stock_Quantity=10
where ProductID='HPL02';
Update Product_Information set In_Stock_Quantity=10
where ProductID='HPP01';
Update Product_Information set In_Stock_Quantity=10
where ProductID='IP6S128G';
Update Product_Information set In_Stock_Quantity=10
where ProductID='IP6S64B';
Update Product_Information set In_Stock_Quantity=10
where ProductID='IP7128R';
Update Product_Information set In_Stock_Quantity=10
where ProductID='IP764B';
Update Product_Information set In_Stock_Quantity=10
where ProductID='IPX128B';
Update Product_Information set In_Stock_Quantity=10
where ProductID='IPX64B';
Update Product_Information set In_Stock_Quantity=10
where ProductID='IPX64W';
Update Product_Information set In_Stock_Quantity=10
where ProductID='LGBS01';
Update Product_Information set In_Stock_Quantity=10
where ProductID='ROGL01';
Technical Design Document Page 18

IDA-MS-TD
Issue 1

• Delete information of a product (Iphone 6S 128GB (Gray) that having


a ProductID as ‘IP6S128G’) by using this following Query:
Delete from Product_Information where
ProductID='IP6S128G'
Now, this product’s information will no longer being available:
Technical Design Document Page 19

IDA-MS-TD
Issue 1

3. SOFTWARE QUERIES (EVIDENCES)

*following queries bellow are written in DML language*

3.1 INSERT QUERIES

/1 Customer_Information table insert query:

INSERT [dbo].[Customer_Information] ([CustomerID],


[Customer_name], [Date_of_Birth], [Customer_address],
[Customer_Gender], [Customer_phone], [Customer_Email]) VALUES

(N'CID001', N'Tran Ngoc Anh', CAST(N'2000-08-08' AS Date), N'299


Tran Hung Dao, Quy Nhon city', N'male', 910923923,
N'anhtn12@gmail.com'),

(N'CID002', N'Ngo Tuan Tu', CAST(N'1992-07-07' AS Date), N'45 Le


Hong Phong, Da Nang city', N'male', 988832833, NULL),

(N'CID003', N'Tran Thi Ngoc Thu', CAST(N'1977-11-21' AS Date),


N'21 Tran Phu, Da Nang city', N'female', 933292494, NULL),

(N'CID004', N'Le Quoc Khai', CAST(N'1996-02-28' AS Date), N'366 Tran


Nhan Tong, Nha Trang city', N'male', 966519419,
N'khaiquoc282@gmail.com'),

(N'CID005', N'Mai Tran Minh Thy', CAST(N'1989-05-17' AS Date), N'21


Hang Xeo, Ha Noi', N'female', 933175571, N'thytrann@gmail.com'),

(N'CID006', N'Ngo Ngoc Thuy Trang', CAST(N'1999-10-25' AS Date),


N'89 Hoang Hoa Tham, Da Nang city', N'female', 983356376,
N'trangngoo@gmail.com'),

(N'CID007', N'Huynh Minh Khoa', CAST(N'1991-12-12' AS Date), N'64 Le


Thanh Ton, Quy Nhon city', N'male', 953345678,
N'khoahuynh@yahoo.com'),

(N'CID008', N'Huynh Nu Thuy Tien', CAST(N'1990-08-30' AS Date),


N'182 Nguyen Nhac, Nha Trang city', N'female', 966782783,
N'thuytien@yahoo.com');

/2 Seller_Information table insert query:

INSERT [dbo].[Seller_Information] ([SellerID], [Seller_Name],


[Seller_Date_of_Birth], [Seller_Gender], [Seller_Address],
[Seller_Phone]) VALUES
Technical Design Document Page 20

IDA-MS-TD
Issue 1

(N'SLID01', N'Ngo Minh Tuan', CAST(N'1989-02-08' AS Date),


N'male', N'203 Phan Boi Chau, Da Nang city', 963310210),

(N'SLID02', N'Kieu Ngoc Trang', CAST(N'1991-06-12' AS Date),


N'female', N'56 Nguyen Thi Thap, Da Nang city', 983356787),

(N'SLID03', N'Hoang Kha Han', CAST(N'1995-08-20' AS Date),


N'female', N'178 Nguyen Huu Trac, Da Nang city', 977709907),

(N'SLID04', N'Le Minh Tri', CAST(N'1994-09-04' AS Date), N'male',


N'341 Hoang Van Thu, Da Nang city', 965510510);

/3 Supplier_Information table insert query:

INSERT [dbo].[Supplier_Information] ([SupplierID],


[Supplier_name], [Supplier_address], [Supplier_phone]) VALUES

(N'SPID01', N'Phong Vu Computer', N'292 Ngo Quyen, Son Tra district,


Da Nang city', 962232456),

(N'SPID02', N'FPT Shop ', N'12 Pasteur, 1st district, HCM city',
968686868),

(N'SPID03', N'The Gioi Di Dong', N'300 Bach Dang, Hai Chau district,
Da Nang city', 909123456),

(N'SPID04', N'X Gear Company', N'66 Nguyen Trai, Hai Chau


district, Da Nang city', 955232464);

/4 Product_Information table insert query:

INSERT [dbo].[Product_Information] ([ProductID], [SupplierID],


[Product_Name], [Calculation_Unit], [Price], [In_Stock_Quantity])
VALUES

(N'CAP01', N'SPID01', N'Cannon Projector 01', N'device',


5000000.0000, 15),

(N'DEL01', N'SPID03', N'Dell Laptop Inspiron 2576', N'pc(s)',


14690000.0000, 8),

(N'HPL01', N'SPID03', N'HP Laptop da0054TU', N'pc(s)',


11000000.0000, 8),

(N'HPL02', N'SPID03', N'HP Laptop Pavilion 14',


N'pc(s)', 13000000.0000, 8),
Technical Design Document Page 21

IDA-MS-TD
Issue 1

(N'HPP01', N'SPID01', N'HP Printer 01', N'machine', 10000000.0000,


8),

(N'IP6S128G', N'SPID02', N'Apple Iphone 6S 128GB (Gray)',


N'pc(s)', 12000000.0000, 10),

(N'IP6S64B', N'SPID02', N'Apple Iphone 6S 64GB', N'pc(s)',


10000000.0000, 10),

(N'IP7128R', N'SPID02', N'Apple Iphone 7 128GB (Red)', N'pc(s)',


18000000.0000, 10),
(N'IP764B', N'SPID02', N'Apple Iphone 7 64GB (Black)', N'pc(s)',
15000000.0000, 10),

(N'IPX128B', N'SPID02', N'Apple Iphone X 128GB (Black)', N'pc(s)',


25000000.0000, 10),

(N'IPX64B', N'SPID02', N'Apple Iphone X 64GB (Black)', N'pc(s)',


22000000.0000, 10),

(N'IPX64W', N'SPID02', N'Apple Iphone X 64GB (White)', N'pc(s)',


22000000.0000, 10),

(N'LGBS01', N'SPID01', N'LG Bluetooth Speaker 01', N'pc(s)',


1500000.0000, 20),

(N'ROGL01', N'SPID04', N'ASUS RoG Gaming Laptop GL503GE',


N'pc(s)', 28000000.0000, 5);

/5 Bill_Information table insert query:

INSERT [dbo].[Bill_Information] ([BillID], [SellerID], [CustomerID],


[Date_of_bill]) VALUES

(N'BID001', N'SLID01', N'CID003', CAST(N'2017-12-31T14:18:32.547' AS


DateTime)),

(N'BID002', N'SLID04', N'CID005', CAST(N'2018-01-09T00:00:00.000' AS


DateTime)),

(N'BID003', N'SLID02', N'CID005', CAST(N'2018-01-10T00:00:00.000' AS


DateTime)),

(N'BID004', N'SLID03', N'CID006', CAST(N'2018-02-20T00:00:00.000' AS


DateTime)),
Technical Design Document Page 22

IDA-MS-TD
Issue 1

(N'BID005', N'SLID01', N'CID007', CAST(N'2018-02-22T00:00:00.000' AS


DateTime)),

(N'BID006', N'SLID01', N'CID001', CAST(N'2018-02-23T00:00:00.000' AS


DateTime)),

(N'BID007', N'SLID01', N'CID002', CAST(N'2018-02-24T00:00:00.000' AS


DateTime)),

(N'BID008', N'SLID04', N'CID001', CAST(N'2018-12-01T00:00:00.000' AS


DateTime));

/6 Bill_Details table insert query:

INSERT [dbo].[Bill_Details] ([BillID], [ProductID], [Sold_Quantity],


[Selling_Price]) VALUES

(N'BID001', N'IPX64W', 1, 23000000.0000),

(N'BID001', N'ROGL01', 1, 30000000.0000),

(N'BID002', N'CAP01', 5, 5500000.0000),

(N'BID003', N'LGBS01', 2, 1600000.0000),

(N'BID004', N'HPL01', 3, 12000000.0000),

(N'BID004', N'HPP01', 1, 12000000.0000),

(N'BID005', N'IPX128B', 1, 27000000.0000),

(N'BID006', N'DEL01', 3, 14990000.0000),

(N'BID007', N'CAP01', 3, 5500000.0000),

(N'BID007', N'HPP01', 2, 12000000.0000);


Technical Design Document Page 23

IDA-MS-TD
Issue 1

3.2 VIEW QUERIES

/1 View 1 Query:

/2 View 2 Query:

/3 View 3 Query:

/4 View 4 Query:

/5 View 5 Query:
Technical Design Document Page 24

IDA-MS-TD
Issue 1

3.3 SELECT QUERIES

• This Select Query will identify Customers who have been purchasing
for ElectroShop’s product more than once:

select b.CustomerID, Customer_Name, Count(BillID) as 'Total


amount of purchases'
from Customer_Information c join Bill_Information b on
c.CustomerID=b.CustomerID
group by b.CustomerID, Customer_name
having Count(BillID) >1

• This Select Query will show Top 3 Highest-purchased Customers:

select top 3 c.CustomerID, Customer_Name, SUM(v1.[In total])


as 'Total amount purchased'
from (Bill_Information bi join view1 v1 on
bi.BillID=v1.BillID) join Customer_Information c on
bi.CustomerID=c.CustomerID
group by c.CustomerID, Customer_name
order by sum(v1.[In total]) desc

• This Select Query will show Top 3 Product that got purchased the most:

select top 3 ProductID, p.Product_Name, SUM(Sold_Quantity) as


'Sold quantity'
from (Product_Information p join view1 v1 on
p.Product_Name=v1.Product_Name)
group by ProductID, p.Product_Name
order by sum(Sold_Quantity) desc
Technical Design Document Page 25

IDA-MS-TD
Issue 1

• This Select Query will indicate the amount of product’s type that got supplied
by each Supplier:

select Supplier_Name, COUNT(p.SupplierID) as 'Types of


product supplied'
from (Product_Information p join Supplier_Information s on
p.SupplierID=s.SupplierID)
group by Supplier_name

• This Select Query will indicate the amount of profit that ElectroShop gets
in each bill.
To get this Query, another View must be created to indicate the total cost
based on original price for each bill:

create view view6 as


SELECT
Bill_Information.BillID, Bill_Details.ProductID,
Bill_Details.Sold_Quantity,
Product_Information.Price,
Bill_Details.Sold_Quantity * Product_Information.Price AS
[Total (Original Price)]
FROM
Bill_Information INNER JOIN Bill_Details ON
Bill_Information.BillID = Bill_Details.BillID INNER JOIN
Product_Information ON
Bill_Details.ProductID = Product_Information.ProductID
Technical Design Document Page 26

IDA-MS-TD
Issue 1

Then, based on the newly-created view (as view 6) and view 1 (which indicated the
total cost based on selling price), this Query will indicate the profit that ElectroShop
will get in each product from each bill by subtracting the Total (Selling price) and Total
(Original price) and save the results as another view named view 7:

create view view7 as


SELECT
view6.BillID, view1.Product_Name,
view6.Sold_Quantity,
view6.[Total (Original Price)],
view1.[In total] AS [Total (Selling Price)],
view1.[In total] - view6.[Total (Original Price)]
AS [Profit]
FROM
view6 INNER JOIN view1 ON
view6.BillID = view1.BillID INNER
JOIN Product_Information ON
view6.ProductID = Product_Information.ProductID AND
view1.Product_Name = Product_Information.Product_Name

After completing view 7, this Query will indicate ElectroShop’s total profit
in each month of each year:

select YEAR(Date_of_Bill) as 'Year',


Month(Date_of_Bill) as 'Month',
sum(view7.Profit) as 'Total profit'
from view7 join Bill_Information on
view7.BillID=Bill_Information.BillID
Group by Year(Date_of_Bill), Month(Date_of_Bill)
Order by Year(Date_of_Bill) desc, Month(Date_of_Bill) desc
Technical Design Document Page 27

IDA-MS-TD
Issue 1