Sie sind auf Seite 1von 39

Student : Le Van Anh

Supervisor : Dr. Van Phi HO


ii
iii
ACKNOWLEDGMENTS

First of all, a special and big thank you goes to my family for giving
encouragement, enthusiasm and invaluable assistant to me. Without all this, I might
not be able to complete this assignment properly.

Secondly, I would like to express my gratitude and appreciation to my


supervisor, Dr. Van Phi HO, who has given his full effort in guiding me in achieving
the learning outcomes as well as his support during working on this assignment.

iv
TABLE OF CONTENT

ACKNOWLEDGMENTS iv

TABLE OF CONTENT v

LIST OF TABLES & FIGURES vii

CHAPTER 1: INTRODUCTION................................................................................1

1.1. Introduction to proposed system......................................................1

1.2. Analysis of the current system..........................................................1

1.3. Assessment of the current system....................................................5

1.3.1. Advantages..................................................................................5

1.3.2. Disadvantages..............................................................................5

1.4. Proposal of a new system................................................................5

CHAPTER 2: SYSTEM OVERVIEW...........................................................................6

2.1. Normalization..................................................................................6

2.2. Entity Relationship Diagram (ERD)....................................................8

CHAPTER 3: SYSTEM DESIGN..............................................................................10

3.1. Design database............................................................................10

3.1.1. SELLER table..............................................................................10

3.1.2. CUSTOMER table........................................................................10

3.1.3. CATEGORY table.........................................................................11

3.1.4. PRODUCT table..........................................................................11

3.1.5. RECEIPT table............................................................................12

v
3.1.6. DETAIL table..............................................................................12

3.2. Create database............................................................................13

3.2.1. ViViShop database......................................................................13

3.2.2. SELLER table..............................................................................13

3.2.3. CUSTOMER table........................................................................14

3.2.4. CATEGORY table.........................................................................14

3.2.5. PRODUCT table..........................................................................15

3.2.6. RECEIPT table............................................................................15

3.2.7. DETAIL table..............................................................................16

3.2.8. Database diagram.......................................................................16

3.3. Manipulate data.............................................................................17

3.4. Create manipulating data views (interfaces)....................................20

3.5. Create displaying data views..........................................................21

3.5.1. Inventory statistics.....................................................................21

3.5.2. Revenue statistics by days...........................................................22

3.5.3. Revenue statistics by sellers........................................................23

3.5.4. Details of a receipt......................................................................23

3.5.5. Customer list statistics................................................................24

CHAPTER 4: TEST CASE AND TEST LOG...............................................................25

4.1. Test case......................................................................................25

4.2. Test log.........................................................................................27

CONCLUSION......................................................................................................31

REFERENCES

vi
LIST OF TABLES & FIGURES

Table 2.1: Normalization of Database Tables..........................................................7


Table 3.1: SELLER table detail..............................................................................10
Table 3.2: CUSTOMER table detail........................................................................11
Table 3.3: CATEGORY table detail........................................................................11
Table 3.4: PRODUCT table detail..........................................................................12
Table 3.5: RECEIPT table detail............................................................................12
Table 3.6: DETAIL table detail..............................................................................13
Table 3.7: Query to create ViViShop database.......................................................13
Table 3.8: Query to create SELLER table...............................................................13
Table 3.9: Query to create CUSTOMER table.........................................................14
Table 3.10: Query to create CATEGORY table.......................................................14
Table 3.11: Query to create PRODUCT table.........................................................15
Table 3.12: Query to create RECEIPT table...........................................................15
Table 3.13: Query to create DETAIL table.............................................................16
Table 3.14: Query to insert data into SELLER table................................................17
Table 3.15: Query to update data.........................................................................17
Table 3.16: Query to delete data..........................................................................17
Table 3.16: Query to create UpdateProduct view...................................................20
Table 3.17: Query to create Stock view................................................................21
Table 3.18: Query to create DailySales view..........................................................22
Table 3.19: Query to create SalesOfSeller view.....................................................23
Table 3.20: Query to create ReceiptDetail view.....................................................24
Table 3.21: Query to create DailySales view..........................................................24
Table 4.1: Test case............................................................................................25
Table 4.2: Test log..............................................................................................27

vii
Table 4.3: Query of recoding................................................................................30

Figure 1.1: A retail receipt sample..........................................................................2


Figure 1.2: Sheets of storing data in the excel file...................................................2
Figure 1.3: The Sell sheet......................................................................................3
Figure 1.4: The Stock sheet...................................................................................4
Figure 1.5: The Boys’ Shirt sheet............................................................................4
Figure 2.1: ERD....................................................................................................9
Figure 3.1: Result as SELLER table.......................................................................13
Figure 3.2: Result as CUSTOMER table.................................................................14
Figure 3.3: Result as CATEGORY table..................................................................14
Figure 3.4: Result as PRODUCT table....................................................................15
Figure 3.5: Result as RECEIPT table.....................................................................15
Figure 3.6: Result as DETAIL table.......................................................................16
Figure 3.7: Result as Diagram..............................................................................16
Figure 3.8: SELLER table with data.......................................................................18
Figure 3.9: CUSTOMER table with data.................................................................18
Figure 3.10: CATEGORY table with data................................................................18
Figure 3.11: PRODUCT table with data.................................................................19
Figure 3.12: RECEIPT table with data...................................................................19
Figure 3.13: DETAIL table with data.....................................................................20
Figure 3.14: UpdateProduct view..........................................................................21
Figure 3.15: Stock view.......................................................................................22
Figure 3.16: DailySales view................................................................................23
Figure 3.17: SalesOfSeller view............................................................................23
Figure 3.18: ReceiptDetail view............................................................................24
Figure 3.19: DailySales view................................................................................24

viii
Design a relational database system for a uniform shop

CHAPTER 1: INTRODUCTION

1.1. Introduction to the proposed system

Vi Vi Shop which is located on Tran Cao Van Street, Da Nang City, is a fashion
shop specializing in selling school uniforms at all grades. They plan to expand sales
online as well as open more branches, so they are looking to apply the current data
storage system with a relational database.

Customers can purchase any quantity of many items that Vi Vi Shop has in its
current catalog. The catalog includes boys' shirt and trousers, girls' shirt and
trousers, dress, and skirt. Each category has many sizes.

Vi Vi Shop would like to add all the customers’ information to the database so
that they can offer more services to their customer, for example, home delivery or
sending an e-mail with offers that are available. So at least one of these contact
method, customer’s address, phone number or email must be entered.

Because of the need to expand the business, sellers’ information also needs to
be stored. Sellers at Vi Vi Shop will be paid a monthly bonus which is determined by
the number of sales they have made for each month.

As well as the monthly sales figures by sellers, Vi Vi Shop wants to be able to


create comparative reports from the system, for example, sales figures for each
month this year compared to last year, or inventory figures for each item.

1.2. Analysis of the current system

The shop currently stores data in two ways: paper books and an excel file.
When a customer buys products, a seller writes a receipt on a paper book and gives
it to the customer. A copy of the receipt is saved and based on that, the shop owner
would aggregate data and store it into the excel file at the end of the day. Below is a
retail receipt form.

Perfomed Student: Instructor: Dr. Van Phi HO 1


Design a relational database system for a uniform shop

Figure 1.1: A retail receipt sample

Information stored on paper receipts includes customer’s name, customer’s


phone number, category, size, quantity, unit price, total price, total value, date.

Figure 1.2: Sheets of storing data in the excel file

All data is stored in an excel file. Excel sheets include Sell sheet, Stock sheet,
Skirt sheet, Dress sheet, etc. in which, Sell sheet stores sales data, Stock sheet
stores input data, the remaining sheets store details about categories. Here are
details of each sheet of the excel file.

Perfomed Student: Instructor: Dr. Van Phi HO 2


Design a relational database system for a uniform shop

Figure 1.3: The Sell sheet

Information stored in Sell sheet is daily sales information including date, item’s
name, quantity sold, total amount, total input value. The shop only stores items with
the common name of HS. Quantity sold is the total products sold by any item. Total
amount is the total turnover of the day. The shop uses the formula in Excel to
calculate the total turnover of all days with the aim of viewing the difference
between revenue and total value of input. The difference would be considered a
profit only when the shop has recovered its capital.

Perfomed Student: Instructor: Dr. Van Phi HO 3


Design a relational database system for a uniform shop

Figure 1.4: The Stock sheet

This sheet contains the shop’s input data. The information stored includes date
received goods, category, size, quantity received, unit price, total price, total value.

Figure 1.5: The Boys’ Shirt sheet

Perfomed Student: Instructor: Dr. Van Phi HO 4


Design a relational database system for a uniform shop

This sheet contains detailed information about boys ’shirt category. This
category has many sizes from small ones such as 9, 10, 11, 12, to bigger ones such
as S, M, 2XL, 3XL, etc. Each size has different stock price, sell price and profit.

1.3. Assessment of the current system

1.3.1. Advantages

Storing data as above is quite simple. Information is clear, meeting the shop's
current needs and purposes.

1.3.2. Disadvantages

Archived information is general, not detailed. There are multiple duplicate data.
This storing method cannot meet new needs or business expansion because of some
disadvantages. For example, the shop can not manage inventory products, specific
sales information or sales on each type of category, each size, etc.

1.4. Proposal for a new system

The above problems can be solved by building a relational database system for
the shop and dividing information that needs to be managed into accurate and clear
tables. The advantages of this database are:

The information is categorized and stored consistently and scientifically.

Relationships can be created between tables, thereby minimizing data


redundancy.

All information can be stored easily and quickly. Then the system would have
enough information to cater to all the needs of the shop, such as checking inventory,
sales statistics by each category, each seller, etc.

Perfomed Student: Instructor: Dr. Van Phi HO 5


Design a relational database system for a uniform shop

CHAPTER 2: SYSTEM OVERVIEW

2.1. Normalization

After analyzing the current way of storing data, the collected information, as
well as the shop's requirements with the database, information to be managed would
include: ReceiptID, Date, SellerID, SellerName, SellerBirthday, SellerAddress,
SellerPhone, SellerEmail, CustomerID, CustomerName, CustomerBirthday,
CustomerAddress, CustomerPhone, CustomerEmail, CategoryID, CategoryName,
ProductID, Size, StockPrice, SellPrice, QuantitySold, QuantityReceived.

StockPrice is the entry price of the product and SellPrice is the price of the sale.
QuantitySold is the quantity sold of the same product in a receipt, and
QuantityReceived is the total items of the same product entered in the warehouse.

With collected information, the database can be normalized as follows:

From UNF to 1NF:

ReceiptID is selected as the primary key for the non-normalized table. The
table needs to be flattened to make sure a table cell contains only one value and
specified the repeating attributes in the non-normalized table for the ReceiptID key
attribute. In a receipt, the attributes: CategoryID, CategoryName, ... repeat several
times so they need to be separated into a new table, DETAIL (ReceiptID,
CategoryID, CategoryName, ProductID, Size, StockPrice, SellPrice, QuantitySold,
QuantityReceived), in which, ReceiptID and ProductID combine to form the
primary key of this new table.

From 1NF to 2NF:

The first table RECEIPT (ReceiptID, Date, SellerID, SellerName, SellerBirthday,


SellerAddress, SellerPhone, SellerEmail, CustomerID, CustomerName,
CustomerBirthday, CustomerAddress, CustomerPhone, CustomerEmail) has the one-
attribute primary key, so it belongs to 2NF.

For the DETAIL table, CategoryID, CategoryName, Size, StockPrice, SellPrice,


QuantityReceived attributes depend partially on the primary key, so they are
separated, combined with the attribute they depend on (ProductID) to form a new

Perfomed Student: Instructor: Dr. Van Phi HO 6


Design a relational database system for a uniform shop

table, PRODUCT. QuantitySold attribute is fully functionally dependent on ReceiptID


and ProductID, so they are preserved in the DETAIL table.

From 2NF to 3NF:

In the RECEIPT table, SellerName, SellerBirthday, SellerAddress, SellerPhone,


SellerEmail attributes have transitive dependencies on the primary key through
SellerID. Therefore they can be separated into a separate table SELLER. Similarly,
the CUSTOMER table can be formed from the following attributes (CustomerID,
CustomerName, CustomerBirthday, CustomerAddress, CustomerPhone,
CustomerEmail). RECEIPT table becomes (ReceiptID, Date, SellerID, CustomerID).

In the PRODUCT table, CategoryName attribute transitively depends on the


primary key through CategoryID. So this table can be separated into CATEGORY
table (CategoryID, CategoryName) and PRODUCT table (ProductID, CategoryID,
Size, StockPrice, SellPrice, QuantityReceived).

The normalization process can be described in the following table:

Table 2.1: Normalization of Database Tables

UNF 1NF 2NF 3NF


ReceiptID ReceiptID ReceiptID ReceiptID
Date Date Date Date
SellerID SellerID SellerID SellerID
SellerName SellerName SellerName CustomerID
SellerBirthday SellerBirthday SellerBirthday SellerID
SellerAddress SellerAddress SellerAddress SellerName
SellerPhone SellerPhone SellerPhone SellerBirthday
SellerEmail SellerEmail SellerEmail SellerAddress
CustomerID CustomerID CustomerID SellerPhone
CustomerName CustomerName CustomerName SellerEmail
CustomerBirthday CustomerBirthday CustomerBirthday CustomerID
CustomerAddress CustomerAddress CustomerAddress CustomerName
CustomerPhone CustomerPhone CustomerPhone CustomerBirthday
CustomerEmail CustomerEmail CustomerEmail CustomerAddress
CategoryID ReceiptID ProductID CustomerPhone

Perfomed Student: Instructor: Dr. Van Phi HO 7


Design a relational database system for a uniform shop

CategoryName ProductID CategoryID CustomerEmail


ProductID CategoryID CategoryName ProductID
Size CategoryName Size CategoryID
StockPrice Size StockPrice Size
SellPrice StockPrice SellPrice StockPrice
QuantitySold SellPrice QuantityReceived SellPrice
QuantityReceived QuantitySold ReceiptID QuantityReceived
QuantityReceived ProductID CategoryID
QuantitySold CategoryName
ReceiptID
ProductID
QuantitySold

After normalization, the database will be organized into the following tables:

RECEIPT (ReceiptID, Date, SellerID, CustomerID)

SELLER (SellerID, SellerName, SellerBirthday, SellerAddress, SellerPhone,


SellerEmail)

CUSTOMER (CustomerID, CustomerName, CustomerBirthday, CustomerAddress,


CustomerPhone, CustomerEmail)

PRODUCT (ProductID, CategoryID, Size, StockPrice, SellPrice, QuantityReceived)

CATEGORY (CategoryID, CategoryName)

DETAIL (ReceiptID, ProductID, QuantitySold)

2.2. Entity Relationship Diagram (ERD)

The following figure shows the ERD of the database after normalization.

Perfomed Student: Instructor: Dr. Van Phi HO 8


Design a relational database system for a uniform shop

Figure 2.1: ERD

In fact, a customer can buy many times and have many receipts. A seller can
sell many times and create many receipts as well. Therefore, the relationships
between Customer and Receipt, between Seller and Receipt are 1 - n.

A category includes many products which are different sizes of the category.
The relationship between Category and Product is also a 1 - n relationship. Each
product sold in each receipt is a value of Detail. A receipt can have many products,
so the relationship between Receipt and Detail is a 1 - n relationship.

Perfomed Student: Instructor: Dr. Van Phi HO 9


Design a relational database system for a uniform shop

CHAPTER 3: SYSTEM DESIGN

3.1. Design database

The database includes separate tables for different objects that make data
management more efficient. Data is managed clearly, consistently. Redundancies can
be avoided while still ensuring data integrity.

Microsoft SQL Server database management system would be used to manage


the shop’s database. As shown in chapter 2, the new database contains 6 tables:
SELLER, CUSTOMER, CATEGORY, PRODUCT, RECEIPT, DETAIL. Details of the tables
are shown below.

3.1.1. SELLER table

This table is used to store sellers’ information. It has 6 columns: SellerID,


SellerName, SellerBirthday, SellerAddress, SellerPhone, SellerEmail, in which, SellerID
is the primary key of the table. Columns must not be empty except SellerEmail. The
value of the SellerBirthday column must be smaller than the data creation date.
Details of the SELLER table are shown in the table below.

Table 3.1: SELLER table detail

Column name Data Type Allow null Contraint


SellerID nvarchar(10) No PK
SellerName nvarchar(50) No
SellerBirthday date No Check (SellerBirthday < getdate())
SellerAddress nvarchar(100) No
SellerPhone nvarchar(15) No
SellerEmail nvarchar(50) Yes

3.1.2. CUSTOMER table

This table is used to store customers’ information. It has 6 columns:


CustomerID, CustomerName, CustomerBirthday, CustomerAddress, CustomerPhone,
CustomerEmail, in which, CustomerID is the primary key of the table. The shop
needs to save at least one of these three contact methods: address, phone number
and email of customers. Therefore, except for the two columns CustomerAddress

Perfomed Student: Instructor: Dr. Van Phi HO 10


Design a relational database system for a uniform shop

and CustomerEmail, the other columns must not be empty. The value of the
CustomerBirthday column must be smaller than the data creation date. Details of the
CUSTOMER table are shown in the table below:

Table 3.2: CUSTOMER table detail

Column name Data Type Allow null Constraint


CustomerID nvarchar(10) No PK
CustomerName nvarchar(50) No
date No Check (CustomerBirthday <
CustomerBirthday
getdate())
CustomerAddress nvarchar(100) Yes
CustomerPhone nvarchar(15) No
CustomerEmail nvarchar(50) Yes

3.1.3. CATEGORY table

This table is used to store categories’ information. It has 2 columns:


CategoryID, CategoryName, in which, CategoryID is the primary key of the table.
Columns cannot be empty. Details of the CATEGORY table are shown in the table
below:

Table 3.3: CATEGORY table detail

Column name Data Type Allow null Constraint


CategoryID nvarchar(10) No PK
CategoryName nvarchar(20) No

3.1.4. PRODUCT table

This table is used to store information of each product. It has 6 columns:


ProductID, CategoryID, Size, StockPrice, SellPrice, QuantityReceived, in which,
ProductID is the primary key of the table. Columns cannot be empty. The values of
StockPrice, SellPrice, and QuantityReceived columns must be greater than 0. Details
of the PRODUCT table are shown in the table below:

Table 3.4: PRODUCT table detail

Allow
Column name Data Type Constraint
null

Perfomed Student: Instructor: Dr. Van Phi HO 11


Design a relational database system for a uniform shop

ProductID nvarchar(10) No PK
CategoryID nvarchar(10) No FK
Size nvarchar(5) No
StockPrice int No Check (StockPrice > 0)
SellPrice int No Check (SellPrice > 0)
Check (QuantityReceived >
QuantityReceived int No
0)

3.1.5. RECEIPT table

This table is used to store basic information of receipts. It has 4 columns:


ReceiptID, Date, SellerID, CustomerID, in which, ReceiptID is the primary key of the
table. Columns cannot be empty. The value of the Date column defaults to the date
of receipt creation. Details of the RECEIPT table are shown in the table below:

Table 3.5: RECEIPT table detail

Column name Data Type Allow null Constraint


ReceiptID nvarchar(10) No PK
Date date No Default (Date = getdate())
SellerID nvarchar(10) No FK
CustomerID nvarchar(10) No FK

3.1.6. DETAIL table

This table is used to store details of receipts. It has 3 columns: ReceiptID,


ProductID, QuantitySold, in which, ReceiptID and ProductID combine to form the
table's primary key. Columns cannot be empty. QuantitySold value must be greater
than 0. Details of DETAIL table are shown in the table below:

Table 3.6: DETAIL table detail

Column name Data Type Allow null Constraint


ReceiptID nvarchar(10) No PK, FK
ProductID nvarchar(10) No PK, FK
QuantitySold tinyint No Check (QuantitySold > 0)

Perfomed Student: Instructor: Dr. Van Phi HO 12


Design a relational database system for a uniform shop

3.2. Create database

3.2.1. ViViShop database

Table 3.7: Query to create ViViShop database

Create Database ViViShop

3.2.2. SELLER table

Table 3.8: Query to create SELLER table

CREATE Table SELLER(


SellerID nvarchar(10) Primary key,
SellerName nvarchar(50) not null,
SellerBirthday date check(SellerBirthday < getdate()) not null,
SellerAddress nvarchar(100) not null,
SellerPhone nvarchar(15) not null,
SellerEmail nvarchar(50))

Figure 3.1: Result as SELLER table

3.2.3. CUSTOMER table

Table 3.9: Query to create CUSTOMER table

CREATE Table CUSTOMER(


CustomerID nvarchar(10) Primary key,
CustomerName nvarchar(50) not null,
CustomerBirthday date check(CustomerBirthday < getdate()) not null,
CustomerAddress nvarchar(100),
CustomerPhone nvarchar(15) not null,
CustomerEmail nvarchar(50))

Perfomed Student: Instructor: Dr. Van Phi HO 13


Design a relational database system for a uniform shop

Figure 3.2: Result as CUSTOMER table

3.2.4. CATEGORY table

Table 3.10: Query to create CATEGORY table

CREATE Table CATEGORY(


CategoryID nvarchar(10) Primary key,
CategoryName nvarchar(20) not null)

Figure 3.3: Result as CATEGORY table

3.2.5. PRODUCT table

Table 3.11: Query to create PRODUCT table

CREATE Table PRODUCT(


ProductID nvarchar(10) Primary key,
CategoryID nvarchar(10) Foreign key references CATEGORY(CategoryID)
on delete cascade on update cascade not null,
Size nvarchar(5) not null,
StockPrice int check(StockPrice > 0) not null,
SellPrice int check(SellPrice > 0) not null,
QuantityReceived int check(QuantityReceived > 0) not null)

Perfomed Student: Instructor: Dr. Van Phi HO 14


Design a relational database system for a uniform shop

Figure 3.4: Result as PRODUCT table

3.2.6. RECEIPT table

Table 3.12: Query to create RECEIPT table

CREATE Table RECEIPT(


ReceiptID nvarchar(10) Primary key,
Date date default getdate() not null,
SellerID nvarchar(10) Foreign key references SELLER(SellerID) on
delete cascade on update cascade not null,
CustomerID nvarchar(10) Foreign key references CUSTOMER(CustomerID)
on delete cascade on update cascade not null)

Figure 3.5: Result as RECEIPT table


3.2.7. DETAIL table

Table 3.13: Query to create DETAIL table

CREATE Table DETAIL(


ReceiptID nvarchar(10) Foreign key references RECEIPT(ReceiptID) on
delete cascade on update cascade,
ProductID nvarchar(10) Foreign key references PRODUCT(ProductID) on
delete cascade on update cascade,
Constraint PKDetail Primary key(ReceiptID, ProductID),
QuantitySold tinyint check(QuantitySold > 0) not null)

Figure 3.6: Result as DETAIL table

Perfomed Student: Instructor: Dr. Van Phi HO 15


Design a relational database system for a uniform shop

3.2.8. Database diagram

Figure 3.7: Result as Diagram

3.3. Manipulate data

Information of the sellers is added to the SELLER table by executing the Insert
statement as follows:

Table 3.14: Query to insert data into SELLER table

INSERT INTO SELLER


VALUES ('S001', 'Le Thi Thanh', '1989-03-22', 'K814/70 Tran Cao
Van', '0905725718', 'thanhlt@gmail.com')
INSERT INTO SELLER
VALUES ('S002', 'Nguyen Xuan Quang', '1997-10-25', '45 Quang
Trung', '0905535515', 'quangnx@gmail.com')
INSERT INTO SELLER
VALUES ('S003', 'Nguyen Van Lam', '1999-02-13', 'K322/63 Hai
Phong', '0931954824', 'lamnv@gmail.com')

The Update statement is used when needing to change data in the table. For
example, below is the query to update the phone number of the seller Nguyen Van
Lam with ID S003 into number 0944561362.

Table 3.15: Query to update data

Perfomed Student: Instructor: Dr. Van Phi HO 16


Design a relational database system for a uniform shop

UPDATE SELLER
SET SellerPhone = '0944561362'
WHERE SellerID = 'S003'

The Delete statement is used to delete a row of a table. The example below is
the query to delete information of the seller with ID S003 from SELLER table.

Table 3.16: Query to delete data

DELETE FROM SELLER


WHERE SellerID = 'S003'

After completing the data entry for the database, the tables containing data are
shown below.

Figure 3.8: SELLER table with data

Figure 3.9: CUSTOMER table with data

Perfomed Student: Instructor: Dr. Van Phi HO 17


Design a relational database system for a uniform shop

Figure 3.10: CATEGORY table with data

Figure 3.11: PRODUCT table with data

Perfomed Student: Instructor: Dr. Van Phi HO 18


Design a relational database system for a uniform shop

Figure 3.12: RECEIPT table with data

Figure 3.13: DETAIL table with data

3.4. Create manipulating data views (interfaces)

The shop needs to update information of products, such as receiving more


items of a certain product or adding information about a new product to the
database. The following view is used to update, add or delete data stored in
PRODUCT table.

Table 3.16: Query to create UpdateProduct view

CREATE View UpdateProduct AS


SELECT * FROM PRODUCT

Perfomed Student: Instructor: Dr. Van Phi HO 19


Design a relational database system for a uniform shop

Figure 3.14: UpdateProduct view

3.5. Create displaying data views

3.5.1. Inventory statistics

Every week, the shop needs to check the remaining quantity of each product in
stock. The following view is used to show statistics of the total number of items sold
and the inventory of each product.

Table 3.17: Query to create Stock view

CREATE View Stock AS


SELECT P.ProductID, CategoryName, Size,
CASE
WHEN SUM(QuantitySold) IS NULL THEN 0
ELSE SUM(QuantitySold)
END
AS TotalSold,
CASE
WHEN (QuantityReceived - SUM(QuantitySold)) IS NULL THEN
QuantityReceived
ELSE QuantityReceived - SUM(QuantitySold)
END
AS QuantityStock
FROM PRODUCT P LEFT OUTER JOIN DETAIL D ON P.ProductID =
D.ProductID INNER JOIN CATEGORY CA ON P.CategoryID = CA.CategoryID
GROUP BY P.ProductID, CA.CategoryName, Size, QuantityReceived

Perfomed Student: Instructor: Dr. Van Phi HO 20


Design a relational database system for a uniform shop

Figure 3.15: Stock view

3.5.2. Revenue statistics by days

The shop wants to know sales and profits every day of the month. The
following view is used to calculate the total number of products sold, the total
revenue and total profit by day in July 2019.

Table 3.18: Query to create DailySales view

CREATE View DailySales AS


SELECT Date, SUM(QuantitySold) AS TotalSold, SUM(SellPrice *
QuantitySold) AS TotalSales, SUM((SellPrice - StockPrice) *
QuantitySold) AS TotalProfit
FROM DETAIL D INNER JOIN PRODUCT P ON D.ProductID = P.ProductID
INNER JOIN RECEIPT R ON D.ReceiptID = R.ReceiptID
WHERE MONTH(Date) = 7 AND YEAR(Date) = 2019
GROUP BY Date

Perfomed Student: Instructor: Dr. Van Phi HO 21


Design a relational database system for a uniform shop

Figure 3.16: DailySales view

3.5.3. Revenue statistics by sellers

At the end of the month, the shop sums up the sales of each seller and gives
bonus money. The following view is used to calculate the total number of products
each seller sold and the total revenue of each seller in July 2019. Results are sorted
in descending order by revenue.

Table 3.19: Query to create SalesOfSeller view

CREATE View SalesOfSeller AS


SELECT TOP (100) PERCENT S.SellerID, SellerName, SUM(QuantitySold)
AS TotalSold, SUM(SellPrice * QuantitySold) AS TotalSales
FROM DETAIL D INNER JOIN PRODUCT P ON D.ProductID = P.ProductID
INNER JOIN RECEIPT R ON D.ReceiptID = R.ReceiptID
INNER JOIN SELLER S ON R.SellerID = S.SellerID
WHERE MONTH(Date) = 7 AND YEAR(Date) = 2019
GROUP BY S.SellerID, SellerName
ORDER BY TotalSales DESC

Figure 3.17: SalesOfSeller view

3.5.4. Details of a receipt

The shop can review all information about a specific receipt. The following view
is used to review the information of a receipt which ReceiptID is R0002.

Perfomed Student: Instructor: Dr. Van Phi HO 22


Design a relational database system for a uniform shop

Table 3.20: Query to create ReceiptDetail view

CREATE View ReceiptDetail AS


SELECT R.ReceiptID, Date, R.SellerID, SellerName, R.CustomerID,
CustomerName, CustomerPhone, CategoryName, Size, QuantitySold,
SellPrice AS UnitPrice, QuantitySold * SellPrice AS TotalPrice
FROM DETAIL D INNER JOIN PRODUCT P ON D.ProductID = P.ProductID
INNER JOIN RECEIPT R ON D.ReceiptID = R.ReceiptID INNER JOIN SELLER
S ON R.SellerID = S.SellerID INNER JOIN CUSTOMER C ON R.CustomerID
= C.CustomerID INNER JOIN CATEGORY CA ON P.CategoryID =
CA.CategoryID
WHERE R.ReceiptID = 'R0002'

Figure 3.18: ReceiptDetail view

3.5.5. Customer list statistics

The shop is going to launch a promotion for loyal customers whose birthday is
in August. Loyal customers are defined as customers who have purchased products
twice or more. The following view lists customers who have purchased at least twice
and have birthday in August.

Table 3.21: Query to create DailySales view

CREATE View CustomerLoyalty AS


SELECT C.CustomerID, CustomerName, CustomerBirthday,
CustomerAddress, CustomerPhone, CustomerEmail, COUNT(R.ReceiptID)
AS NumberOfPurchase
FROM RECEIPT R INNER JOIN CUSTOMER C ON R.CustomerID = C.CustomerID
WHERE MONTH(CustomerBirthday) = 8
GROUP BY C.CustomerID, CustomerName, CustomerBirthday,
CustomerAddress, CustomerPhone, CustomerEmail
HAVING COUNT(R.ReceiptID) >= 2

Figure 3.19: DailySales view

Perfomed Student: Instructor: Dr. Van Phi HO 23


Design a relational database system for a uniform shop

CHAPTER 4: TEST CASE AND TEST LOG

4.1. Test case

Table 4.1: Test case

What is
Tes
being How Test data used Expected results
t
tested
Failure when inputting
Data of a new
Reverse the order data into RECEIPT
Order of receipt in
of data entry as table, an error
input RECEIPT table:
1 follows: message box appears
on data entry ‘R0010’, ‘2019-
1. Receipt table because there is no
screen 08-19’, ‘S004’,
2. Seller table Seller ‘S004' assigned
‘C0005’
in SELLER table
Failure when inputting
Data of a new
Reverse the order data into PRODUCT
Order of product in
of data entry as table, an error
input PRODUCT table:
2 follows: message box appears
on data entry ‘P020’, ‘BO’, ‘11’,
1. Product table because there is no
screen ‘70000’,
2. Category table Category ‘BO' assigned
‘100000’, ‘50’
in CATEGORY table
Data of a new
customer in Failure when inputting
Enter a value that
CUSTOMER data into CUSTOMER
has more than 10
table: table, an error
Validation of characters into
3 ‘C0000000009’ message box appears
input CustomerID
, ‘Nguyen Van A’, because the limit of
column of
‘1997-09-03’, ’50 CustomerID length is
CUSTOMER table
Le Do’, 10 characters
‘0977888999’
Data of a new Failure when inputting
Enter a real product in data into PRODUCT
Validation of number into PRODUCT table: table, an error
4
input StockPrice column ‘P020’, ‘GD’, ‘11’, message box appears
of PRODUCT table ’65.500’, because StockPrice's
‘95000’, ‘50’ data type is integer
5 Validation of Enter a value into Data of a new Failure when inputting
input Date column of receipt in data into RECEIPT
RECEIPT table in RECEIPT table: table, an error
mm-dd-yyyy ‘R0010’, ’08-13- message box appears

Perfomed Student: Instructor: Dr. Van Phi HO 24


Design a relational database system for a uniform shop

because Date’s data


2019’, ‘S001’,
format type receives the value
‘C0005’
in dd-mm-yyyy format
Data of a new Failure when inputting
Do not enter a seller in SELLER data into SELLER table,
value into table: an error message box
Validation of
6 SellerName ‘S004’, ’’, ‘1997- appears because
input
column of SELLER 09-03’, ’50 Le SellerName column
table Do’, does not allow null
‘0977888999’ values
Failure when inputting
Data of a new data into RECEIPT
receipt in table, an error
Duplicate data of
Validation of RECEIPT table: message box appears
7 ReceiptID column
input ‘R0009’, ‘2019- because ReceiptID is
of RECEIPT table
08-19’, ‘S003’, the primary key that
‘C0005’ does not receive
duplicate values
Enter values for
two rows of
Data of a new
DETAIL table that
detail in DETAIL
Validation of either their Success when inputting
8 table:
input Receipt ID or data into DETAIL table
‘R0009’,
Product ID are
‘P009’, ‘1’
different from
each other
Failure when inputting
Enter values for data into DETAIL table,
Data of a new
two rows of an error message box
detail in DETAIL
Validation of DETAIL table with appears because
9 table:
input the same value of ReceiptID and
‘R0009’,
ReceiptID and ProductID combined
‘P009’, ‘2’
ProductID are the primary keys of
DETAIL table
Success when inputting
Data of a new
Do not enter a data into RECEIPT
receipt in
Validation of value into Date table, Date column
10 RECEIPT table:
input column of receives default value
‘R0010’, ‘’,
RECEIPT table that is the date of
‘S001’, ‘C0005’
receipt creation
11 Validation of Enter a value that Data of a new Failure when inputting
input is an integer and product in data into PRODUCT
less than 0 into PRODUCT table: table, an error
SellPrice column ‘P020’, ‘GD’, ‘11’, message box appears

Perfomed Student: Instructor: Dr. Van Phi HO 25


Design a relational database system for a uniform shop

because SellPrice has


’70000’, an constraint that
of PRODUCT table
‘-95000’, ‘50’ SellPrice must be
greater than 0
Enter a value that Data of a new
is an integer and product in
Success when inputting
Validation of greater than 0 PRODUCT table:
12 data into PRODUCT
input into SellPrice ‘P020’, ‘GD’, ‘11’,
table
column of ’70000’,
PRODUCT table ‘95000’, ‘50’
Failure when inputting
Enter values for data into PRODUCT
Data of a new
two rows of table, an error
product in
PRODUCT table message box appears
Validation of PRODUCT table:
13 with the same because different
input ‘P021’, ‘GD’,
value of products must be
‘11’, ’70000’,
CategoryID and different categories or
‘100000’, ‘50’
Size same category but
different sizes
Failure when inputting
Enter values for data into PRODUCT
Data of a new
two rows of table, an error
product in
Retest PRODUCT table message box appears
PRODUCT table:
14 validation of with the same because different
‘P021’, ‘GD’,
input value of products must be
‘11’, ’70000’,
CategoryID and different categories or
‘100000’, ‘50’
Size same category but
different sizes

4.2. Test log

Table 4.2: Test log

Action
Test Expected results Date Actual results
taken
1 Failure when inputting 13-08- An error message box appeared: None
data into RECEIPT 2019
table, an error
message box appears
because there is no
Seller ‘S004'
assigned in SELLER
table

Perfomed Student: Instructor: Dr. Van Phi HO 26


Design a relational database system for a uniform shop

An error message box appeared:


Failure when inputting
data into PRODUCT
table, an error
message box appears 13-08-
2 None
because there is no 2019
Category ‘BO'
assigned in
CATEGORY table

An error message box appeared:


Failure when inputting
data into CUSTOMER
table, an error
13-08-
3 message box appears None
2019
because the limit of
CustomerID length is
10 characters

An error message box appeared:


Failure when inputting
data into PRODUCT
table, an error 13-08-
4 None
message box appears 2019
because StockPrice's
data type is integer

Failure when inputting An error message box appeared:


data into RECEIPT
table, an error
message box appears 13-08-
5 None
because Date’s data 2019
type receives the
value in dd-mm-yyyy
format

Perfomed Student: Instructor: Dr. Van Phi HO 27


Design a relational database system for a uniform shop

An error message box appeared:


Failure when inputting
data into SELLER
table, an error
13-08-
6 message box appears None
2019
because SellerName
column does not allow
null values

An error message box appeared:


Failure when inputting
data into RECEIPT
table, an error
message box appears 13-08-
7 None
because ReceiptID is 2019
the primary key that
does not receive
duplicate values

Success when
13-08-
8 inputting data into Success when inputting data None
2019
DETAIL table
Failure when inputting An error message box appeared:
data into DETAIL
table, an error
message box appears
13-08-
9 because ReceiptID None
2019
and ProductID
combined are the
primary keys of
DETAIL table
Success when
inputting data into
RECEIPT table, Date Success when inputting data,
13-08-
10 column receives Date column receives default None
2019
default value that is value ‘13-08-2019’
the date of receipt
creation
11 Failure when inputting 13-08- An error message box appeared: None
data into PRODUCT 2019
table, an error
message box appears
because SellPrice has
an constraint that

Perfomed Student: Instructor: Dr. Van Phi HO 28


Design a relational database system for a uniform shop

SellPrice must be
greater than 0

Success when
13-08-
12 inputting data into Success when inputting data None
2019
PRODUCT table
Failure when inputting
data into PRODUCT
table, an error
message box appears
13-08- Recode
13 because different Success when inputting data
2019 & Retest
products must be
different categories or
same category but
different sizes
An error message box appeared:
Failure when inputting
data into PRODUCT
table, an error
message box appears
13-08-
14 because different None
2019
products must be
different categories or
same category but
different sizes

Different products must be different categories or same category but different


sizes. When performing test 13, the product 'P021' is a size 11 girl's dress, duplicate
to the product P020 added in test 12. This does not make sense, so it is necessary to
recode and retest. The UNIQUE constraint must be added into PRODUCT table. The
query of recoding is shown below.

Table 4.3: Query of recoding


ALTER Table PRODUCT
ADD Constraint UniqueProduct Unique(CategoryID, Size)

Perfomed Student: Instructor: Dr. Van Phi HO 29


Design a relational database system for a uniform shop

CONCLUSION

Databases provide information essential for any day-to-day operation. They


stand as the back-end of most systems. Therefore, Database Design & Development
is a fundamental and essential skill for IT students to master.

After studying Database Design & Development and working on this


assignment, I have learned a lot. I not only understand the concepts and issues
relating to database design and development such as data integrity, data validation,
data consistency, data security and advanced database querying facilities across
multiple tables, testing the system against the user and system requirements; but
also have the practical skills to translate that understanding into the design and
creation of databases. After that, I have been able to use Microsoft SQL Server to
design and develop a relational database system for a uniform shop.

Moreover, by doing actual research on a shop to understand how they store


data, analyzing the advantages and disadvantages of the system, and coming up
with solutions to problems, I am able to develop skills such as communication,
critical thinking, analysis, reasoning and interpretation, which are crucial for further
developing academic and employee competence.

However, because of limited knowledge and time, the system was built quite
simple and has not been able to put to use in practice yet. The lack of user-friendly
interface makes it difficult for users to use. Due to no practical experience, this
system is not really complete and there are still many points to be improved to meet
the actual needs of users. During my next study at BTEC, I will work hard to develop
this database into a mature application that can be used in practice.

Perfomed Student: Instructor: Dr. Van Phi HO 30


Design a relational database system for a uniform shop

REFERENCES

[1] Dr. Van Phi Ho’s lecture notes

REFERENCES 1

Das könnte Ihnen auch gefallen