GCD1102 Asm2

You might also like

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

ASSIGNMENT 2 FRONT SHEET

Qualification TEC Level 5 HND Diploma in Computing

Unit number and title Unit 04: Database Design & Development

Submission date October 26, 2022 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Phùng Hữu Minh Khánh Student ID GDD210033

Class GCD1102 Assessor name Do Duy Thao

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 Km

Grading grid

P2 P3 P4 P5 M2 M3 M4 M5 D2 D3

PHÙNG HỮU MINH KHÁNH 1


❒ Summative Feedback: ❒ Resubmission Feedback:

Grade: Assessor Signature: Date:


Signature & Date:

PHÙNG HỮU MINH KHÁNH 2


Table of Contents
I. Develop the database system with evidence of user interface, output, data validations, and querying across multiple tables. (P2) .. 8
A. User Interface...................................................................................................................................................................................... 8
1. Main menu from of the program. ................................................................................................................................................... 8
2. Order Manager From ....................................................................................................................................................................... 9
3. Customer Manager From .............................................................................................................................................................. 10
4. Chef Manager From ....................................................................................................................................................................... 11
5. Bill Manager From ......................................................................................................................................................................... 12
6. Food Manager From ...................................................................................................................................................................... 13
B. Output. .............................................................................................................................................................................................. 14
C. Data validation. ................................................................................................................................................................................. 20
• Data type. ........................................................................................................................................................................................ 20
• Field properties. .............................................................................................................................................................................. 22
• NULL Constraint in SQL. .................................................................................................................................................................. 22
• SQL PRIMARY KEY Constraint. ........................................................................................................................................................ 23
• SQL FOREIGN KEY Constraint. ......................................................................................................................................................... 23
• Identity. ........................................................................................................................................................................................... 24
D. Query across multiple tables. ........................................................................................................................................................... 24
II. Implement a query language into the relational database system. (P3) ............................................................................................. 26
2.1. Queries to SELECT data with illustrations of the final result. ........................................................................................................ 26
2.2. Queries to UPDATE data with illustrations of the final result........................................................................................................ 29

PHÙNG HỮU MINH KHÁNH 3


2.3. Queries to DELETE data with illustrations of the final result. ........................................................................................................ 30
III. Test the system. (P4)............................................................................................................................................................................ 31
A. Test plan. ........................................................................................................................................................................................... 31
B. Test results. ....................................................................................................................................................................................... 33
IV. Produce technical and user documentation. (P5) ............................................................................................................................... 35
• Technical document. .......................................................................................................................................................................... 35
• User document. .................................................................................................................................................................................. 37
References ................................................................................................................................................................................................ 43

PHÙNG HỮU MINH KHÁNH 4


Table of Figures

Figure 1: Main Menu From. ........................................................................................................................................................................ 8


Figure 2: Order Manager From. .................................................................................................................................................................. 9
Figure 3: Customer Manager From. .......................................................................................................................................................... 10
Figure 4: Chef Manager From. .................................................................................................................................................................. 11
Figure 5: Bill Manager From...................................................................................................................................................................... 12
Figure 6: Food Manager From. ................................................................................................................................................................. 13
Figure 7: Add Dish successfully. ................................................................................................................................................................ 13
Figure 8: Create a database. ..................................................................................................................................................................... 14
Figure 9: Create Table Customer. ............................................................................................................................................................. 14
Figure 10: Create Table Chef..................................................................................................................................................................... 15
Figure 11: Create Table Food. ................................................................................................................................................................... 15
Figure 12: Create Table Bill. ...................................................................................................................................................................... 15
Figure 13: Create Table Order. ................................................................................................................................................................. 15
Figure 14: Insert data for the Customer Table. ........................................................................................................................................ 16
Figure 15: Insert Data for the Food Table. ................................................................................................................................................ 16
Figure 16: Insert Data for the Chef Table. ................................................................................................................................................ 17
Figure 17: Insert Data for the Order Table. .............................................................................................................................................. 18
Figure 18: Insert Data for the Bill Table. ................................................................................................................................................... 19
Figure 19: Diagram of the relationship between the Tables. ................................................................................................................... 19
Figure 20: Field properties validation example. ....................................................................................................................................... 22
Figure 21: Example of NULL Constraint in the Bill Table. ......................................................................................................................... 22
Figure 22: PRIMARY KEY in the Food Table. ............................................................................................................................................. 23
Figure 23: Identity in Customer Table. ..................................................................................................................................................... 24
Figure 24: Query 1..................................................................................................................................................................................... 25
Figure 25: Result of Query 1. .................................................................................................................................................................... 25

PHÙNG HỮU MINH KHÁNH 5


Figure 26: Query 2..................................................................................................................................................................................... 25
Figure 27: Result of Query 2. .................................................................................................................................................................... 25
Figure 28: Query 3..................................................................................................................................................................................... 26
Figure 29: Result of Query 3. .................................................................................................................................................................... 26
Figure 30: Select Table. ............................................................................................................................................................................. 27
Figure 31: Customer Table. ....................................................................................................................................................................... 27
Figure 32: Bill Table. .................................................................................................................................................................................. 27
Figure 33: Order Table. ............................................................................................................................................................................. 28
Figure 34: Food Table................................................................................................................................................................................ 28
Figure 35: Chef Table. ............................................................................................................................................................................... 29
Figure 36: Update data for CustomerId=2. ............................................................................................................................................... 29
Figure 37: Before Update data. ................................................................................................................................................................ 29
Figure 38: After Update Data. ................................................................................................................................................................... 30
Figure 39: Delete date from Order Table. ................................................................................................................................................ 30
Figure 40: Before Delete data. .................................................................................................................................................................. 30
Figure 41: After Delete data. .................................................................................................................................................................... 30
Figure 42: Update data for Bill Table. ....................................................................................................................................................... 31
Figure 43: After Update data. ................................................................................................................................................................... 31
Figure 44: Entity Relationship Diagram of Restaurant Management System. ......................................................................................... 36
Figure 45: Home Screen window. ............................................................................................................................................................. 37
Figure 46: Customer Manager Window.................................................................................................................................................... 38
Figure 47: Order Manager Window. ......................................................................................................................................................... 39
Figure 48: Chef Manager Window. ........................................................................................................................................................... 39
Figure 49: Food Manager Window. .......................................................................................................................................................... 40
Figure 50: Bill Manager Window. ............................................................................................................................................................. 40
Figure 51: Window when Dish added successfully. .................................................................................................................................. 41

PHÙNG HỮU MINH KHÁNH 6


Figure 52: Logo in Home Screen Window................................................................................................................................................. 42

Table of Tables

Table 1: Table of Data type INT. ............................................................................................................................................................... 20


Table 2: Table of Data type Varchar(Size). ............................................................................................................................................... 20
Table 3: Table of Data type Nvarchar. ...................................................................................................................................................... 21
Table 4: Order Table. ................................................................................................................................................................................ 23
Table 5: Bill Table. ..................................................................................................................................................................................... 24
Table 6: Table of Test Plan. ....................................................................................................................................................................... 32
Table 7: Test Result. .................................................................................................................................................................................. 34

PHÙNG HỮU MINH KHÁNH 7


I. Develop the database system with evidence of user interface, output, data validations, and
querying across multiple tables. (P2)
A. User Interface
1. Main menu from of the program.
As the main form of the software, the supporting tools are fully displayed on it for the easiest user
management and use. At startup, users such as managers or chefs and employees will be required to log in
to be able to use the system.

Figure 1: Main Menu From.

PHÙNG HỮU MINH KHÁNH 8


2. Order Manager From
When the user clicks on the Order item, the Order window will appear. Next it will display information about
BillId, FoodId, Order time, quantity and total price according to OrderId. In addition, users can edit, add new
Orders and delete them then save them.

Figure 2: Order Manager From.

PHÙNG HỮU MINH KHÁNH 9


3. Customer Manager From
When the user clicks on the Customer item, the Customer window will appear. Next it will display Customer
information including Id, FullName and phone number and the user presses save it will save to the system. In
addition, users can edit, add new Customers and delete them and save them in the system.

Figure 3: Customer Manager From.

PHÙNG HỮU MINH KHÁNH 10


4. Chef Manager From
When the user clicks on the Chef item, the Chef window will appear. Next it will display the Chef information
including their Id, FullName and address and the user presses save it will save to the system. In addition,
users can edit, add new Chefs and delete them and save them in the system.

Figure 4: Chef Manager From.

PHÙNG HỮU MINH KHÁNH 11


5. Bill Manager From
When the user clicks on the Bill item, the Bill window will appear. Next it will display information about that
Bill including BillId, CustomerId, Date, table number and Total amount of Customer. There is also a scroll bar
to view the Bill information below. Moreover, the Bill window has functions such as delete, add, edit and
save.

Figure 5: Bill Manager From.

PHÙNG HỮU MINH KHÁNH 12


6. Food Manager From
When the user clicks on the Food item, the Food window will display. Next it will display information about
the dish such as Id, Name, Chef Id, classification and unit price of each dish. The Food window has the same
functions as the Bill window.

Figure 6: Food Manager From.

• The screen shows the result Add dish successfully, which means the dish information has been
successfully added to the database.
• Similar to the Add dish action, other actions will be performed similarly.

Figure 7: Add Dish successfully.

PHÙNG HỮU MINH KHÁNH 13


=> Based on the user interface that I designed above, we can see that the system has a full range of Create, Edit, Save,
Delete functions as required. In addition, each category has its own management page for users to easily make
changes such as the Chef, Food, etc. management page, as well as manage and print the payment Bill. Specific and
clear features as well as simple interface avoid distracting users

B. Output.
• Create Database: The Create Database statement is used to create a new SQL database. The Use command allows
specific databases to be used. Newly built database will be used here.

Figure 8: Create a database.

• Create Table: The Create Table statement is used to create a new table in the database. The column parameters
specify the names of the columns in the table. The data type parameter specifies the type of data the column can
hold (e.g., varchar, integer, date, etc.). To add to the table, you must use Replace, and you cannot delete those
constraints in the revision table.

Figure 9: Create Table Customer.

PHÙNG HỮU MINH KHÁNH 14


Figure 10: Create Table Chef.

Figure 11: Create Table Food.

Figure 12: Create Table Bill.

Figure 13: Create Table Order.

PHÙNG HỮU MINH KHÁNH 15


• Insert Into: The insert Into statement is used to insert new records in the table. After creating the table with the
name table as stated, I will insert the data about the information and the tables as follows:

Figure 14: Insert data for the Customer Table.

Figure 15: Insert Data for the Food Table.

PHÙNG HỮU MINH KHÁNH 16


Figure 16: Insert Data for the Chef Table.

PHÙNG HỮU MINH KHÁNH 17


Figure 17: Insert Data for the Order Table.

PHÙNG HỮU MINH KHÁNH 18


Figure 18: Insert Data for the Bill Table.

• The diagram of the relationship between the tables for the SQL database built by SQL and queries is shown below:

Figure 19: Diagram of the relationship between the Tables.

PHÙNG HỮU MINH KHÁNH 19


C. Data validation.
• Data type.
In this article I have used the following data types:
o INT: INT stands for an integer. A medium integer. Signed range is from -2147483648 to 2147483647.
Unsigned range is from 0 to 4294967295. The size parameter specifies the maximum display width (which is
255). An integer can be 0, positive or negative. (w3schools, SQL Data types, 2022)
Data Type Range Storage
-231 (-2,147,483,648) to
INT 231-1 (2,147,483,647) 4 Bytes

Table 1: Table of Data type INT.

o VARCHAR (Size): A variable length string (can contain letters, numbers, and special characters). The following
illustrates the syntax: VARCHAR(n). In this syntax, n defines the string length from 1 to 8,000. In this syntax,
the maximum storage size is 231-1 bytes (2 GB). In general, the storage size of a VARCHAR value is the actual
length of the data stored plus 2 bytes. (sqlservertutorial, SQL Server VARCHAR, 2022)
Data type Description Range Storage
Varchar A variable 8,000 2 bytes + number of
length string characters chars

Table 2: Table of Data type Varchar(Size).

o NVARCHAR: SQL Server NVARCHAR data type is used to store variable-length, Unicode string data. The
following shows the syntax of NVARCHAR(n). In this syntax, n defines the string length that ranges from 1 to
4,000. If you don’t specify the string length, its default value is 1. (sqlservertutorial, SQL Server NVARCHAR,
2022)

PHÙNG HỮU MINH KHÁNH 20


Nvarchar
Character Data Type Variable-length, both Unicode
and non-Unicode characters
such as Japanese, Korean, and
Chinese.
Maximum Length Up to 4,000 characters
Character Size Takes up 2 bytes per
Unicode/Non-Unicode
character
Storage Size 2 times Actual Length (in
bytes)
Usage Due to storage only, used only
if you need Unicode support
such as the Japanese Kanji or
Korean Hangul characters.
Table 3: Table of Data type Nvarchar.

o DATE: To store the date data in the database, you use the SQL Server DATE data type. You use the SQL Server
DATE data type. the DATE data type has only the date component. The range of a DATE value is from January
1, 1 CE (0001-01-01) through December 31, 9999 CE (9999-12-31). It takes 3 bytes to store a DATE value.
(sqlservertutorial, SQL Server DATE, 2022)
In this format:
o YYYY is four digits that represent a year, which ranges from 0001 to 9999.
o MM is two digits that represent a month of a year, which ranges from 01 to 12.
o DD is two digits that represent a day of the specified month, which ranges from 01 to 31,
depending on the month.

PHÙNG HỮU MINH KHÁNH 21


o DATATIME: The DATETIME data type stores instant time expressed as a calendar date and time of day. You
choose how exactly the DATETIME value is stored; Its accuracy can range from a year to a fraction of a
second. DATETIME stores a data value as a contiguous string of fields representing each unit of time (year,
month, day, etc.)
• Field properties.
Some field properties restrict data entry. For example, the name of a chef or customer is a field that restricts input
by limiting the number of string data to a length less than or equal to 50.

Figure 20: Field properties validation example.

• NULL Constraint in SQL.


A field with a NULL value is a field with no value. If a field in a table is optional, it is possible to insert a new record
or update a record without adding a value to this field. Then, the field will be saved with a NULL value.
o For example, we have the following simple create table statement that is used to define the Bill table. This
table contains four columns: BillID, CustomerId, Date, and Total. In the Total column definition statement,
the SQL NULL column-level constraint is enforced, treating the Total column as an optional column with an
SQL value. If null possibility is not specified while defining the column, it will accept NULL value by default:

Figure 21: Example of NULL Constraint in the Bill Table.

PHÙNG HỮU MINH KHÁNH 22


• SQL PRIMARY KEY Constraint.
The PRIMARY KEY constraint uniquely identifies each record in a table. Primary keys must contain UNIQUE values,
and cannot contain NULL values. A table can have only ONE primary key; and in the table, this primary key can
consist of single or multiple columns (fields). The following SQL creates a PRIMARY KEY on the "FoodId" column
when the Food table is created:

Figure 22: PRIMARY KEY in the Food Table.

• SQL FOREIGN KEY Constraint.


The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables. A FOREIGN KEY is
a field (or collection of fields) in one table, that refers to the PRIMARY KEY in another table. The table with the
foreign key is called the child table, and the table with the primary key is called the referenced or parent table.
Look at the following two tables:

Table 4: Order Table.

PHÙNG HỮU MINH KHÁNH 23


Table 5: Bill Table.

• Identity.
In SQL Server, Identity column of a table is a column whose value increases automatically. The value in an identity
column is created by the server. A user generally cannot insert a value into an identity column. Identity column can
be used to uniquely identify the rows in the table.

Figure 23: Identity in Customer Table.

D. Query across multiple tables.


In this part, I will use some basic queries like:
• SELECT statement: Gets specific records from one or more tables. In the example below I will get the Customer
Table:

PHÙNG HỮU MINH KHÁNH 24


Figure 24: Query 1.

Figure 25: Result of Query 1.

• Get all the information about the Food in the name starting in "B":

Figure 26: Query 2.

Figure 27: Result of Query 2.

• Use JOIN to accomplish some of the following tasks:

PHÙNG HỮU MINH KHÁNH 25


o Show chef name and information about dishes: To perform this action I will JOIN two tables Chef and Food
to get chef name and information about dishes.

Figure 28: Query 3.

Figure 29: Result of Query 3.

II. Implement a query language into the relational database system. (P3)
2.1. Queries to SELECT data with illustrations of the final result.
After adding data to the tables, we can use the SELECT statement to verify the information:
• As an example, use the following query to select all tables in the system, including Customer, Bill, Order, and Food
and Chef.

PHÙNG HỮU MINH KHÁNH 26


Figure 30: Select Table.

Figure 31: Customer Table.

Figure 32: Bill Table.

PHÙNG HỮU MINH KHÁNH 27


Figure 33: Order Table.

Figure 34: Food Table.

PHÙNG HỮU MINH KHÁNH 28


Figure 35: Chef Table.

2.2. Queries to UPDATE data with illustrations of the final result.


• If any information is incorrect or needs to be corrected during data import, we can use the UPDATE statement to
update the correct information.
o For example, if a user wants to update CustomerId = 2 information with the new name, gender, and phone
number information, we use the following query:

Figure 36: Update data for CustomerId=2.

Figure 37: Before Update data.

PHÙNG HỮU MINH KHÁNH 29


Figure 38: After Update Data.

2.3. Queries to DELETE data with illustrations of the final result.


• If a dish is ordered wrong, the staff or the cashier can delete the data about that OrderId with the Detele command
to avoid customer complaints.
o As an example: We run the following query when a user wants to delete information with OrderId = 20.

Figure 39: Delete date from Order Table.

Figure 40: Before Delete data.

Figure 41: After Delete data.

PHÙNG HỮU MINH KHÁNH 30


Figure 42: Update data for Bill Table.

Figure 43: After Update data.

III. Test the system. (P4)


A. Test plan.
• In this test, I will use the data provided in P2 to test cases in the Restaurant management system.

Test Expected
Content Times
Case Result
1 Insert data into the tables 1 Pass
2 Update data in the tables 1 Pass
3 Delete data of the tables 1 Pass
4 Select data into the table 1 Pass
Find dishes that start with
5 1 Pass
the word ‘Bun’
Print and sort dishes from
6 1 Pass
expensive to cheap
Calculate the total amount
7 of all Bills from 10/10 to 1 Pass
13/10

PHÙNG HỮU MINH KHÁNH 31


Show customer name along
8 with total amount and table 1 Pass
number.
Show chef name along with
9 1 Pass
dishes that their cook.
Show list female customers
10 with information about their 1 Pass
order and total.
Table 6: Table of Test Plan.

PHÙNG HỮU MINH KHÁNH 32


B. Test results.
Test
Statu
Cas SQL Code Expected Result Test Result
s
e
The Chef table will
display the data inserted
(ChefId(identity),
1 Pass
FullName, Gender,
Address) of ChefId 1, 2
and 3.
The Customer phone
number with CustomerId
2 Pass
= 10 will be replace to a
new phone number.
In the Order List, there
3 Pass
will be no OrderId = 20
The SQL System will
display the data table of
Order Table if staffs or
4 managers want to see Pass

The SQL System will find


and display the data
5 Pass
table with start with
word ‘Bun’
The SQL System will print
6 and sort dishes from Pass
expensive to cheap

PHÙNG HỮU MINH KHÁNH 33


The SQL System will
display the count of
7 number of Bills form Pass
2022-10-10 to 2022-10-
13. It has 7 bills.
The SQL System will
display name of
8 customer with Table Pass
number and Total of
their bill.
The SQL System will
display name of chefs
9 with name of food and Pass
category and unit price if
other chefs want to see
The SQL System will
display female customers
10 and information related Pass
to their Order and their
Bill
Table 7: Test Result.

PHÙNG HỮU MINH KHÁNH 34


IV. Produce technical and user documentation. (P5)
Technical document.
A. Introduction.
• The purpose of this study is to build a database system. This topic is Design and Development of Noel Restaurant
Management System in university campus. The development will proceed from step by step by collecting
information then implementing a complete system to meet the needs of customers as well as restaurant
management. Schedule updates and maintenance to prepare for problems related to data and information on the
system.
• Situation: Student numbers are increasing at universities, universities are accepting more students, and the need
for on-campus restaurants to relax and eat is increasing. Due to the fast growth rate, the restaurant's management
system often makes mistakes and is difficult to manage. For that reason, this project aims to make restaurant
management easier, more convenient and efficient than before. In addition, this project also helps the restaurant
to manage more necessary things in the restaurant, so that the restaurant can develop in the future right on the
university campus.
B. User Requirement.
This section was created to describe the management system features that the database system can expose to the
user. The fully designed Noel Restaurant Management System will have the following features:
• Customers: All customer information must have a unique CustomerId for those customers to be found
throughout the database. Customers must provide their name, gender and phone number to the system.
• Bill: All information about the bill must have a unique BillId to avoid the duplication of other Bills. In addition, it
is possible to issue a bill to the customer at the time of payment. Bill includes information about customerId,
table number, payment date and time and total.
• Order: All Orders have a unique OrderId and each Bill can be Ordered more than once. Order information
includes BillId to identify the caller, FoodId, order date and time, quantity and total amount of that dish.
• Chef: Each chef always has a unique chefId so that those chefs can be found in the system database. Chef must
provide full name, gender and residential address.

PHÙNG HỮU MINH KHÁNH 35


• Food: All dishes have a separate FoodId to avoid duplicate dishes. In addition, dishes can be found and modified
in the system database. The dishes include information such as dish name, chef's id, classification and their unit
price.
C. Diagram.

Figure 44: Entity Relationship Diagram of Restaurant Management System.

PHÙNG HỮU MINH KHÁNH 36


User document.
• As soon as you enter the system, the options below the taskbar will appear, including Customer, Order, Bill,
Dishes and Chef. There is also an Exit button to exit. Return to the main screen and click on the logo in each
selected item.

Figure 45: Home Screen window.

PHÙNG HỮU MINH KHÁNH 37


• The Customer management window includes a place to enter Customer information and Add, Edit, Delete and
Save. Below will display employee information.

Figure 46: Customer Manager Window.

PHÙNG HỮU MINH KHÁNH 38


• The same goes for the Chef. Food and Order management window.

Figure 47: Order Manager Window.

Figure 48: Chef Manager Window.

PHÙNG HỮU MINH KHÁNH 39


Figure 49: Food Manager Window.

• In the bill management window, the window will display information about the bill. When clicking, it will show
Total on the right to see the amount clearly. The bill includes the Id of the customer sitting at the table number
and date and time sitting there and the total amount.

Figure 50: Bill Manager Window.

PHÙNG HỮU MINH KHÁNH 40


Figure 51: Window when Dish added successfully.

PHÙNG HỮU MINH KHÁNH 41


• The Logo in Home Screen section has the following contents:
❖ List of statistics that the user wants to see.
❖ Click on itself to see the data.

Figure 52: Logo in Home Screen Window.

PHÙNG HỮU MINH KHÁNH 42


References

1. Anon (n.d.) SQL Data Types, SQL data types for mysql, SQL Server, and MS access, [online] Available at:
https://www.w3schools.com/sql/sql_datatypes.asp (Accessed October 24, 2022).

2. Anon (2020) SQL Server Data types, SQL Server Tutorial, [online] Available at: https://www.sqlservertutorial.net/sql-server-
basics/sql-server-data-types/ (Accessed October 24, 2022).

3. Anon (n.d.) SQL Primary Key Constraint, [online] Available at: https://www.w3schools.com/sql/sql_primarykey.asp (Accessed
October 24, 2022).

PHÙNG HỮU MINH KHÁNH 43

You might also like