Tải bản đầy đủ (.pdf) (30 trang)

Assignment 1 Database Design Development (1622 Distinction)

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (3.52 MB, 30 trang )

ASSIGNMENT 1 FRONT SHEET
Qualification

TEC Level 5 HND Diploma in Computing

Unit number and title

Unit 04: Database Design & Development

Submission date

Date Received 1st submission

Re-submission Date

Date Received 2nd submission

Student Name

Bui Quang Minh

Student ID

GCD210325

Class

GCD1104

Assessor name


Ho Van Phi

Student declaration
I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I
understand that making a false declaration is a form of malpractice.
Student’s signature
Grading grid

P1

M1

D1

Minh


 Summative Feedback:

Grade:
Lecturer Signature:

Assessor Signature:

 Resubmission Feedback:

Date:


Table of Contents

CHAPTER 1: STATEMENTS OF USER AND SYSTEM REQUIREMENTS (P1) ................................................... 5
I. OVERVIEW .............................................................................................................................................. 5
1. Introduction of proposed system ....................................................................................................... 5
2. Analysing current system ................................................................................................................... 5
3. Evaluating current system .................................................................................................................. 6
4. Proposal of new system ...................................................................................................................... 7
II. APPLICATION REQUIREMENT ................................................................................................................. 7
1. Hardware requirement ....................................................................................................................... 7
2. Software requirement ......................................................................................................................... 8
CHAPTER 2: DESIGN THE RELATIONAL DATABASE SYSTEM (P1-D1) .......................................................... 8
I. ANALYSING REQUIREMENTS.................................................................................................................... 8
II. DATABASE DESING with EXPLAINATIONS ............................................................................................... 9
III. REVIEW IF DATABASE IS NORMALIZED .................................................................................................. 9
IV. DATA VALIDATION ............................................................................................................................... 10
1. Products table .................................................................................................................................... 10
2. Customers table ................................................................................................................................. 10
3. Staffs table ......................................................................................................................................... 11
4. Orders table ....................................................................................................................................... 11
5. Details table ....................................................................................................................................... 12
6. Suppliers table ................................................................................................................................... 12
V. WIREFRAME OF APPLICATION .............................................................................................................. 13
1. Creating tables using tool .................................................................................................................. 13
2. Creating tables using command ........................................................................................................ 14
3. Database diagram .............................................................................................................................. 16


4. Sample data ....................................................................................................................................... 16
4.1 Sample data of CUSTOMERS table …….......................................................................................... 16
4.2 Sample data of STAFFS table ……….…….......................................................................................... 17
4.3 Sample data of PRODUCTS table ……............................................................................................. 18

4.4 Sample data of ORDERS table ……................................................................................................. 19
4.5 Sample data of DETAILS table ……................................................................................................. 19
4.6 Sample data of SUPPLIERS table ……............................................................................................. 20
5. View for each table ............................................................................................................................ 21
5.1 View of PRODUCTS table ……........................................................................................................ 21
5.2 View of CUSTOMERS table ……...................................................................................................... 21
5.3 View of STAFFS table ……............................................................................................................... 22
5.4 View of ORDERS table ……............................................................................................................. 22
5.5 View of DETAILS table ……............................................................................................................. 22
5.6 View of SUPPLIERS table ……......................................................................................................... 23
6. Query ................................................................................................................................................. 23
6.1 Query to show products from 10m to 20m ……............................................................................ 23
6.2 Query to show income of order at a date …………………………......................................................... 24
6.3 Query to show income of all order ……………………………………………………........................................ 24
7. View tables ........................................................................................................................................ 24
7.1 View to managing products …….................................................................................................... 24
7.2 View of revenue ragarding year ................................................................................................... 25
7.3 View of revenue ragarding Products ............................................................................................ 26
7.4 View of revenue made from staffs ............................................................................................... 26
7.5 View of orders placed by customers ............................................................................................ 27
7.6 View of orders number made by staffs ........................................................................................ 28
7.7 View of available products ........................................................................................................... 28
VI. Assess the effectiveness of the design .............................................................................................. 29
Reference list ......................................................................................................................................... 30


CHAPTER 1: STATEMENTS OF USER AND SYSTEM
REQUIREMENTS (P1)
I. OVERVIEW
1. Introduction of proposed system

FPT Shop has contacted my firm where I am working as a Database developer because the
increasing number of stores. FPT Shop are having many challenges that it has to handle
throughout the nation. It has made decision to create a new database with many purposes with
different objects such as users can sign in with phone numbers and other data, supervisors can
manage their stores and director board can view all information from all stores.

2. Analysing current system
The FPT Shop currently stores all data in excel files when a customer purchases an item, a staff
will write that item’s information into a particular paper called receipt and give it to the
customer. All available items and purchased items also store in excel files.

Figure 1. Product table’s data in excel


After a day, month, or year, staff will create a new table to calculate the total amount of money
earned and reckon up the quantity, the following table made in excel:

Figure 2. Revenue in January

3. Evaluating current system
Advantages of Spreadsheets










Spreadsheets require minimal training.
Spreadsheets are customizable.
Spreadsheets can be more collaborative than other tools.
It’s easy to manipulate and analyze data.
You can integrate spreadsheets with specific tools.
Spreadsheets are quick and easy to add to a workflow.
Spreadsheets are fantastic tools for financial documents.
You have access to countless spreadsheet templates.


Disadvantages of Spreadsheets








Spreadsheets are not secure.
It’s hard to tell who edited the spreadsheet.
There will be multiple versions of the truth.
Visualizing data is difficult.
Critical customer data is at everyday life's mercy.
There’s no native integration with business systems.
Spreadsheets make it harder for managers to manage team members.

4. Proposal of new system
By creating a relational database system for the shop and organizing the information that has to
be maintained into precise and understandable tables, the above issues may be resolved for

the following benefits:








Minimum data redundancy
Improved data security
Increased consistency
Lower updating errors
Reduced costs of data entry, data storage, and data retrieval
Improved data access using host and query languages
Higher data integrity from application programs

II. APPLICATION REQUIREMENTS
1. Hardware requirement
Hard Disk
 SQL Server requires a minimum of 6 GB of available hard-disk space.
Monitor
 SQL Server requires Super-VGA (800x600) or higher resolution monitor
Memory: Minimum
 Express Editions: 512 MB
 All other editions: 1 GB
Processor Speed: Minimum
 x64 Processor 1.4 GHz

2. Software requirement

Operating system
 Windows 10 TH1 1507 or greater
 Windows Server 2016 or greater
.NET Framework
 Minimum operating systems includes minimum .NET framework.


CHAPTER 2: DESIGN THE RELATIONAL DATABASE SYSTEM
(P1 – D1)
I. ANALYSING THE REQUIREMENTS
As a client/customer,
- I want to view the detail of the product so that I can select that product.
- I want to order products so that I can buy those products.
- I want to check my products/items so that I can make sure that products are mine.
- I want to log in and log out the system so that I can use all the functions.
- I want to follow my order so that I can keep track of it.
- I want to know the origin of products so that I can buy it wihout hesitation.
As a staff,
- I want to input the products’ data so that I can manage the products.
- I want to alter/modify products’ data so that I can update the products.
- I want to approve the customers’ order so that the orders can be delivered.
- I want to follow clients’ orders so that I can let them know about their orders.
- I want to view the clients’ feedbacks so that I can support or report to the higher
position.
- I want to supervise the supply so that I can check the quantity of products and ensure
the quality of products.
As a manager,
- I want to manage the staff so that I can supervise the staff.
- I want to view the list of products so that I can manage the products.
- I want to view the daily/monthly/weekly revenue so that I can manage the

income/money of my shop.
- I want to check staff’s attendance so that I can pay their salary.
So, I can define all tables what I need. They are
1. Products (ProductID, ProductName, Price, Quantity, SupplierID)
2. Orders (OrderID, OrderDate, CustomerID, StaffID)
3. Customers (CustomerID, CustomerName, Address, PhoneNumber)
4. Staffs (StaffID, StaffName, Address, Salary)
5. Details (OrderID, ProductID, Price, Quantity)
6. Suppliers (SupplierID, SupplierName)


II. DATABASE DESIGN with EXPLANATIONS

Figure 3. ERD Diagram

The picture above shows the relational entity diagram of FPTSHOP system through the ERD
diagram, we can see the following relationships:
 The Customer entity has a 1-to-many relationship with orders because a customer can
place many orders. In contrast, a specific order is placed by just a customer.


The Staff entity has a 1-to-many relationship with orders because a staff can organize
many orders. In contrast, a specific order is created by just a staff.



The Supplier entity has a 1-to-many relationship with Product because a supplier can
provide many kinds of items. In contrast, a product is supplied by just a supplier.




The Products entity has a 1-to-many relationship with Details because an item can
contain many details. In contrast, a detail is contained by an item.



The Orders entity has a 1-to-many relationship with Details because an order can
contain many separately details. In contrast, a detail is contained in an order.

III. REVIEW IF DATABASE IS NORMALIZED
From ERD Diagram shown above, we can see that the Products table contains transitive functional
Dependence so that it cannot achieve 3NF (The third normal form):
ProductID  SupplierID  SupplierName
To achieve 3NF, attribute ‘SupplierName’ needs to split from PRODUCTS in order to combine with
SupplierID and then create a new table named SUPPLIERS.


As the result, after normalizing, the database system contains the following tables
1. Products (ProductID, ProductName, Price, Quantity, SupplierID)
2. Orders (OrderID, OrderDate, CustomerID, StaffID)
3. Customers (CustomerID, CustomerName, Address, PhoneNumber)
4. Staffs (StaffID, StaffName, Address, Salary)
5. Details (OrderID, ProductID, Price, Quantity)
6. Suppliers (SupplierID, SupplierName)

IV. DATA VALIDATION
1. Products table
Products Table: this table is used to store all information about products. It has several columns
such as ProductID, ProductName, Price, Quantity… Among these, productID is the primary key.
The column productName must be not null and the Price, Quantity must be bigger than zero

(>0). The detail of the table Products is shown as follow:
Column name
ProductID
ProductName
Price
Quantity
SupplierID

Data Tye

Allow null

Contraint

Nvarchar(10)

No

PK

Nvarchar(100)

No

Unique

Int

Yes


Check (Price>0)

Int

Yes

Check (quantity>0)

Nvarchar(10)

No

FK (Suppliers)

Table 1. Products table

2. Customers table
Customers Table: this table is used to store all information of customers. It has several columns
such as CustomerID, CName, Address, PhoneNum… Among these, CustomerID is the primary
key. The columns CName and Address must not be null. The detail of the table Customers is
shown as follows:
Column name
CustomerID
CName

Data Tye

Allow null

Contraint


Nvarchar(10)

No

PK

Nvarchar(100)

No


Address
PhoneNum

Nvarchar(150)

No

Nvarchar(11)

Yes

Table 2. Customers table

3. Staffs table
Staffs Table: this table is used to store all information about staff. It has several columns such
as StaffID, SName, Address, Salary… Among these, StaffID is the primary key. The columns
SName and Address must not be null and and Salary must be bigger than zero (>0). The detail of
the table Staffs is shown as follows:

Column name
StaffID
SName
Address
Salary

Data Tye

Allow null

Contraint

Nvarchar(10)

No

PK

Nvarchar(100)

No

Nvarchar(150)

No

Int

Yes


Check (Salary>0)

Table 3. Staffs table

4. Orders table
Orders Table: this table is used to store all information on orders. It has several columns such
as OrderID, OrderDate, CustomerID, StaffID… Among these, StaffID is the primary key. The
columns' OrderDate must not be null. The detail of table Orders is shown as follows:
Column name
OrderID
OrderDate
CustomerID
StaffID

Data Tye

Allow null

Contraint

Nvarchar(10)

No

PK

Date

No


Nvarchar(10)

No

FK from Customers

Nvarchar(10)

No

FK from Staffs

Table 4. Orders table


5. Details table
Details Table: this table is used to store all information of all details. It has several columns such
as OrderID, ProductID, Price, Quantity… Among these, OrderID and ProductID are the primary
keys and the Price, Quantity must be bigger than zero (>0).. The detail of table Details is shown
as follows:
Column name
OrderID
ProductID
Price
Quantity

Data Tye

Allow null


Contraint

Nvarchar(10)

No

PK-FK from Orders

Nvarchar(10)

No

PK-FK from Products

Int

No

Check (Price>0)

Int

No

Check (quantity>0)

Table 5. Details table

6. Suppliers table
Suppliers Table: this table is used to store all information of all suppliers. It has two columns

including SupplierID and SupplierName. Among these, SupplierID is the primary keys. The detail
of table Suppliers is shown as follows:
Column name
SupplierID
SupplierName

Data Tye

Allow null

Contraint

Nvarchar(10)

No

PK

Nvarchar(100)

No

Table 6. Suppliers table


V. WIREFRAME OF APPLICATION
1. Creating Tables using tool

Figure 4. Products table


Figure 5. Customers table

Figure 6. Staffs table


Figure 7. Orders table

Figure 8. Details table

Figure 9. Suppliers table

2. Creating tables using command
CREATE TABLE PRODUCTS
(
ProductID NVARCHAR(10) PRIMARY KEY,
PName NVARCHAR(50) NOT NULL UNIQUE,
Price INT CHECK(Price>0),
Quantity INT CHECK(Quantity>0)
SupplierID nvarchar(10) REFERENCES SUPPLIERS (SupplierID)
)
GO

Figure 10. Products table using command


CREATE TABLE CUSTOMERS
(
CustomerID NVARCHAR(10) PRIMARY KEY,
CName NVARCHAR(100) NOT NULL,
Address NVARCHAR (150) NOT NULL,

PhoneNum NVARCHAR (11)
)
GO

Figure 11. Customers table using command
CREATE TABLE STAFFS
(
StaffID NVARCHAR(10) PRIMARY KEY,
SName NVARCHAR(100) NOT NULL,
Address NVARCHAR (150) NOT NULL,
Salary INT CHECK(Salary>0)
)
GO

Figure 12. Staffs table using command
CREATE TABLE ORDERS
(
OrderID NVARCHAR(10) PRIMARY KEY,
OrderDate DATE NOT NULL,
CustomerID NVARCHAR(10) REFERENCES CUSTOMERS (CustomerID),
StaffID NVARCHAR(10) REFERENCES STAFFS (StaffID)
)
GO

Figure 13. Orders table using command
CREATE TABLE DETAILS
(
OrderID NVARCHAR(10) REFERENCES ORDERS (OrderID),
ProductID NVARCHAR(10) REFERENCES PRODUCTS (ProductID),
Price INT CHECK(Price>0),

Quantity INT CHECK(Quantity>0)
CONSTRAINT PK_DETAIL PRIMARY KEY (OrderID, ProductID)
)
GO

Figure 14. Details table using command
CREATE TABLE SUPPLIERS
(
SupplierID nvarchar(10) PRIMARY KEY,
SupplierName nvarchar(50)
)

Figure 15. Suppliers table using command


3. Database diagram

Figure 16. Database diagram

4. Sample data
4.1 Sample data of Customers table
INSERT INTO DBO.CUSTOMERS
'0905905716')
GO
INSERT INTO DBO.CUSTOMERS
'0859454746')
GO
INSERT INTO DBO.CUSTOMERS
'0122616888')
GO

INSERT INTO DBO.CUSTOMERS
'0318887166')
GO
INSERT INTO DBO.CUSTOMERS
GO

VALUES ('0100', N'Bùi Quang Tường', N'11 Ngô Quyền',
VALUES ('0101', N'Bùi Thị Thu tuyền', N'50 Ngô Quyền',
VALUES ('0102', N'Huỳnh Văn Tú', N'122 Nguyễn Trưng',
VALUES ('0103', N'Nguyễn Thị Anh', N'59 Trần Phú',
VALUES ('0104', N'Lê Bá Lộc', N'25 Trần Phú', '0706162561')


Figure 17. Data of customers

4.2 Sample data of staff table
INSERT INTO DBO.STAFFS
GO
INSERT INTO DBO.STAFFS
GO
INSERT INTO DBO.STAFFS
GO
INSERT INTO DBO.STAFFS
Trung’,9000000)
GO
INSERT INTO DBO.STAFFS

VALUES ('1123', N'Bùi Quang Minh', N'78 Lê Tấn Trung', 23000000)
VALUES ('2123', N'Trần Thị Thu Hà', N'50 Nam Thọ', 15000000)
VALUES ('3123', N'Hoàng Văn Nam', N'60 Lê Duẩn', 17000000)

VALUES ('1223', N'Phạm Thị Đài Trang', N'80 Lê Tấn
VALUES ('2223', N'Phan Tuyết Nhung', N'77 Lê Đức Thọ', 5000000)

GO

Figure 18. Data of staff


4.3 Sample data of Products table
INSERT
GO
INSERT
GO
INSERT
GO
INSERT
GO
INSERT
GO
INSERT
GO
INSERT
GO
INSERT
GO
INSERT
GO
INSERT

INTO DBO.PRODUCTs VALUES ('IP14', 'Iphone 14', 23000000, 10, 'APP')

INTO DBO.PRODUCTs VALUES ('IP14PM', 'Iphone 14 Pro Max', 36000000, 25, 'APP')
INTO DBO.PRODUCTs VALUES ('IP13', 'Iphone 13', 18400000, 55, 'APP')
INTO DBO.PRODUCTs VALUES ('IP13M', 'Iphone 13 Mini', 25200000, 5, 'APP')
INTO DBO.PRODUCTs VALUES ('GZFlip4', 'Galaxy Z Flip4', 32400000, 2, 'SS')
INTO DBO.PRODUCTs VALUES ('GZFold4', 'Galaxy Z Fold4', 55600000, 7, 'SS')
INTO DBO.PRODUCTs VALUES ('RN12', 'Redmi Note 12', 11000000, 40, 'Mi')
INTO DBO.PRODUCTs VALUES ('RN12P', 'Redmi Note 12 Pro', 14260000, 45, 'Mi')
INTO DBO.PRODUCTs VALUES ('OR8P', 'Oppo Reno 8 Pro', 1900000, 45, 'OPP')
INTO DBO.PRODUCTs VALUES ('Vv23', 'Vivo V23', 9990000, 45, 'Vi')

GO

Figure 19. Data of all products


4.4 Sample data of Orders table
INSERT
GO
INSERT
GO
INSERT
GO
INSERT
GO
INSERT
GO
INSERT

INTO DBO.ORDERS VALUES ('111', '2023-01-1', '0100', '2123')
INTO DBO.ORDERS VALUES ('112', '2023-01-2', '0101', '3123')

INTO DBO.ORDERS VALUES ('113', '2022-12-30', '0103', '2223')
INTO DBO.ORDERS VALUES ('114', '2022-12-25', '0104', '2223')
INTO DBO.ORDERS VALUES ('115', '2022-11-1', '0104', '1223')
INTO DBO.ORDERS VALUES ('116', '2022-10-17', '0102', '2123')

GO

Figure 20. Data of orders placed

4.5 Sample data of Details table
INSERT
GO
INSERT
GO
INSERT
GO
INSERT
GO
INSERT
GO
INSERT
GO

INTO DBO.DETAILS VALUES ('111', 'IP14', 23000000, 5)
INTO DBO.DETAILS VALUES ('112', 'IP13M', 25200000, 7)
INTO DBO.DETAILS VALUES ('113', 'OR8P', 1900000, 12)
INTO DBO.DETAILS VALUES ('114', 'RN12P', 14260000, 17)
INTO DBO.DETAILS VALUES ('115', 'Vv23', 9990000, 20)
INTO DBO.DETAILS VALUES ('116', 'GZFold4', 55600000, 2)



Figure 21. Data of orders’ details

4.6 Sample data of Suppliers table
INSERT
GO
INSERT
GO
INSERT
GO
INSERT
GO
INSERT

INTO DBO.SUPPLIERS VALUES ('APP', 'Apple')
INTO DBO.SUPPLIERS VALUES ('SS', 'SamSung')
INTO DBO.SUPPLIERS VALUES ('Mi', 'Xiaomi')
INTO DBO.SUPPLIERS VALUES ('OPP', 'OPPO')
INTO DBO.SUPPLIERS VALUES ('Vi', 'Vivo')

GO

Figure 22. Data of suppliers



×