You are on page 1of 42

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 04: Database Design & Development

Submission date Aug – 26th - 2021 Date Received 1st submission Aug – 26th - 2021

Re-submission Date Date Received 2nd submission

Student Name Dang Tan Tai Student ID BSAF200013

Class PBIT16101_CNTT1 Assessor name Lam Hong Thanh

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

P2 P3 P4 P5 M2 M3 M4 M5 D2 D3
❒ Summative Feedback: ❒ Resubmission Feedback:

Grade: Assessor Signature: Date:


Signature & Date:
Learning Outcomes and Assessment Criteria

Pass Merit Distinction

LO2 Develop a fully functional relational database system, based on an existing system design.

LO3 Test the system against user and system requirements.

LO4 Produce technical and user documentation

P2 Develop the database M2 Implement a fully functional LO2 & 3

system with evidence of user database system which includes D2 Evaluate the effectiveness of

interface, output and data system security and database the database solution in relation

validations, and querying maintenance. to user and system

across multiple tables. requirements, and suggest

M3 Assess whether meaningful improvements.

P3 Implement a query data has been extracted through

language into the relational the use of query tools to produce

database system. appropriate management

information.

P4 Test the system against M4 Assess the effectiveness of

user and system the testing, including an

requirements. explanation of the choice of test

data used.

P5 Produce technical and M5 Produce technical and user D3 Assess any future

user documentation. documentation for a fully improvements that may be

required to ensure the continued


functional system, including ER
effectiveness of the database
Diagram and normalization
system.
statements and describing how

the system works.

Table of Contents
I. Implementation (P2) 6
1. Code snippets to create each table 8
2. Code snippets to insert some sample data for each table 3
3. Generated Database Diagram of implementation 10
4. Explanations about any changes comparing to design 10

II. User Interfaces and Queries (P3) 11


1. Each user interface 11
2. Queries to support the functionalities 16
3. Queries to support enhancement of the interface to above function (Search) 23

III. Testing (P4) 27


IV. Technical Document (P5) 35
1. Introduction 35
2. ERD 35
3. Possible and realistic improvements 37
4. Current version number 37
5. Date last changed and implemented 37
V. User Document (P5) 37
1. Introduction 37
2. The user interfaces 37
3. Step by step how to achieve the functionality provided, for all paths though solution
40
4. Data validation needed 40
VI. References List 42
I. Implementation (P2)
1. Code snippets to create each table
In this part, We are going to use a database management system MariaDB – Heidi SQL same
SQL Sever and MySQL, because my laptop has some problem and could not install SQL Sever,
That is the reason why I use Heidi SQL instead SQL Sever, and do not worry about that thing
because it look like SQL Sever.
To create table in Database we could use the syntax statement “CREATE TABLE ” and set the
name after this command statement. For example, In my assignment 01 the issues give to
create a database for FPT University about attendance students. And we have 4 tables are
Students, Subjects, Room and Attendances
Now, I would like to create table Students have 2 property full name and student ID, set
studentId is primary key, I could use the statement like this:

CREATE TABLE Students (


studentId INT NOT NULL PRIMARY KEY,
fullname VARCHAR(50) NOT NULL
);
And the result can display in Database:

Secondly, I would like to create next Table is Rooms have 2 properties roomId and nameRoom
and set roomId is primary key, I could use the statement in below:

CREATE TABLE ROOM (


roomId INT NOT NULL PRIMARY KEY,
nameRoom VARCHAR(50) NOT NULL
);

Result:
Thirdly, Follow the statement to create table subjects have studentID, subjectID,
nameSubjects, startDate, endDate and set subjectID is primary key, set studentID is foreign
key in below:

CREATE TABLE Subjects (


subjectId INT NOT NULL PRIMARY KEY,
studentId INT NOT NULL FOREIGN KEY REFERENCES students(studentId),
nameSubjects VARCHAR(50) NOT NULL,
startDate VARCHAR(50) NOt NULL,
endDate VARCHAR(50) NOT NULL
);

Result:

Finally, I would like to create table Attendances to attendance students have 5 properties are
subjectID, studentID and are foreign key then attendanceID going to primary key:
CREATE TABLE Attendances (
attendanceId INT NOT NULL PRIMARY KEY,
subjectId INT NOT NULL,
roomId INT NOT NULL,
studentId INT NOT NULL,
attendanceDate VARCHAR(50) NOT NULL,
attendanceStatus BOOL,
FOREIGN KEY(roomId) REFERENCES ROOM(roomId),
FOREIGN KEY(studentId) REFERENCES students(studentId),
FOREIGN KEY(subjectId) REFERENCES subjects(subjectId)
);
Result:

2. Code snippets to insert some sample data for each table


Now, We are going to insert some value into each table, We would like to use syntax The SQL
INTO Statement is used to insert new records in a table
INSERT INTO syntax:
INSER INTO table_name (Column1, Column 2, …. Column N ) VALUES (value1, value2,.valueN)
Now, We have to know the syntax to insert data into table of database
We could use it to insert sample data into table Students:
INSERT INTO students (studentId, fullname) VALUES (1,'Dang tan tai');
INSERT INTO students (studentId, fullname) VALUES (2,'Nguyen Quoc Hung');
INSERT INTO students (studentId, fullname) VALUES (3,'Do Xuan Loc');
INSERT INTO students (studentId, fullname) VALUES (4,'Tran Dai');

The result shall display in table:


After I would like to insert some value in Room table:
INSERT INTO room (roomID, nameRoom) VALUES (1,'ROOM 101');
INSERT INTO room (roomID, nameRoom) VALUES (2,'ROOM 102');
INSERT INTO room (roomID, nameRoom) VALUES (3,'ROOM 103');
INSERT INTO room (roomID, nameRoom) VALUES (4,'ROOM 104');

Result:

Insert value into subjects table:


INSERT INTO subjects (subjectID, studentId, nameSubjects, startDate,
endDate) VALUES (1,1,'Programming','Aug-25-2020','Dec-25-2020');
INSERT INTO subjects (subjectID, studentId, nameSubjects, startDate,
endDate) VALUES (2,2,'Networking','Aug-25-2020','Dec-25-2020');
INSERT INTO subjects (subjectID, studentId, nameSubjects, startDate,
endDate) VALUES (3,3,'Programming','Aug-25-2020','Dec-25-2020');

INSERT INTO subjects (subjectID, studentId, nameSubjects, startDate,


endDate) VALUES (4,4,'Professional Pratice','Aug-25-2020','Dec-25-2020');

Result:

Insert some value into attendances table to attendance students:


INSERT INTO attendances (attendanceId, subjectId, roomId,studentId,
attendanceDate, attendanceStatus) VALUES (1,1,1,1,'Aug-25-2020',0);
INSERT INTO attendances (attendanceId, subjectId, roomId,studentId,
attendanceDate, attendanceStatus) VALUES (2,2,2,2,'Aug-25-2020',0);
INSERT INTO attendances (attendanceId, subjectId, roomId,studentId,
attendanceDate, attendanceStatus) VALUES (3,3,3,3,'Aug-25-2020',1);
INSERT INTO attendances (attendanceId, subjectId, roomId,studentId,
attendanceDate, attendanceStatus) VALUES (4,4,4,4,'Aug-25-2020',1);

Note: Status to attendance students is 0 and 1, If the value is 1, The status will Present and
otherwise
Result:

3. Generated Database Diagram of implementation


The ERD diagram of implementation in Database:

4. Explanations about any changes comparing to design


In my database, I have some problem about data types and I have changed data types in
Primary Key ID all the table, and I am going to add auto increment to Primary Key and convert
status data type in Attendances Table from Boolean to Integer.
Table student going to add three properties is Address, Day Of Birth, Major

II. User Interfaces and Queries (P3)


1. Each User Interfaces
The Student Interfaces are adding student have two input text to fill in and have four buttons
for four functions:

In the User Adding student, I am going to insert some data in text fill
And click on button has text “Add new Student” and the result will return same like this:

The data has insert into table, When we are clicking on button “Add new student” the button
is going to call the syntax SQL “INSERT INTO (fullname,address,dob,major) VALUES (‘Lam
Hong Thanh’,’Phuong 26, Binh Thanh, TP. HCM’,’09-01-2009’,’Technical Lead’)” and then the
data is going to save to student table in database
Some User Interface for each other functions
View details Information:
Delete students

Update information student


Registration Subjects for student have ID 2:

Result:
The User Interface for attendance:

The user interface to add room to study:


2. Queries to support the functionalities
In the button “Add”, This is a button to add data from User Interface to Database, the
statement add would have syntax “ INSERT INTO (Column 1, Column 2, …. Column N) VALUES
(Value 1, Value 2, …. Value N).
I would like to add some information of student at student table and the queries for insert
value is going to same the statement in below:
INSERT INTO students (studentId, fullname, address,dob, Major) VALUES
(10,'Lam Hong Thanh','Phuong 26, Binh thanh, TP.HCM','Oct-09-
2009','Technical Lead');
INSERT INTO students (studentId, fullname, address,dob, Major) VALUES
(11,'Lam Hong B','Phuong 26, Binh thanh, TP.HCM','Oct-09-
2009','Programming');
INSERT INTO students (studentId, fullname, address,dob, Major) VALUES
(9,'Lam Hong C','Phuong 26, Binh thanh, TP.HCM','Oct-09-2009','Networking');

And I would like to watch the student data in table student and I am using the syntax:
SELECT * FROM STUDENTS
The result after the above syntax:

In my table we have some value is null in other column and I want to click on “Update” button
Data will update. Firstly I would like to update information of student have studentID equal 1
and the syntax I would like to use for this case is:

The SQL UPDATE Statement


The UPDATE statement is used to modify the existing records in a table.
Syntax:
UPDATE table_name SET column1 = value1,  column2 = value2, ...
WHERE condition;
I am going to update student have ID = 1 and going to same in below:
UPDATE students SET fullname='Nguyen Quoc Hung', address = 'Trang Bom, Dong
Nai', dob = 'Apri-15-2001', major='Information Technology'
WHERE studentId=1;
The result:

Finally, I want to click on “Delete” button and delete the data, In the above table I have two
rows have null column at address, dob and major, and I would like to delete all of them, the
syntax delete is going to like this:

DELETE FROM table_name WHERE condition;


And I am going to delete 2 students have id = 9
DELETE FROM students WHERE studentId = 9;
SELECT * FROM students;
Result:

But I would like to delete one more student have id = 10:


DELETE FROM students WHERE studentId = 10;
SELECT * FROM students;
Result:
All student always has subjects and I would like to insert some value, and all the student have
major Information Technology need to register 3 subjects is “Programming, Networking,
Database” and click on “Add” in the U.I Subjects:

INSERT INTO subjects (subjectId,studentId, nameSubjects, startDate, endDate)


VALUES (5,4,'Programming','May-01-2021','Sep-01-2021');
INSERT INTO subjects (subjectId,studentId, nameSubjects, startDate, endDate)
VALUES (1,1,'Programming','Aug-25-2020','Dec-25-2020');
INSERT INTO subjects (subjectId,studentId, nameSubjects, startDate, endDate)
VALUES (2,2,’Networking’,'Aug-25-2020','Dec-25-2020');
INSERT INTO subjects (subjectId,studentId, nameSubjects, startDate, endDate)
VALUES (3,3,’Programming’,'Aug-25-2020','Dec-25-2020');

SELECT * FROM subjects;


The result at table subjects:

I would like to add some student in a room have same their major when I click on “Add”
button in U.I:
Insert some data into database have table room in SQL:
INSERT INTO room (roomId,nameRoom, time, studentId) VALUES
(101,'R101','9:00-13:00',1);
INSERT INTO room (roomId,nameRoom, time, studentId) VALUES
(102,'R102','9:00-13:00',2);
INSERT INTO room (roomId,nameRoom, time, studentId) VALUES
(103,'R103','9:00-13:00',3);
INSERT INTO room (roomId,nameRoom, time, studentId) VALUES
(104,'R104','9:00-13:00',4);
INSERT INTO room (roomId,nameRoom, time, studentId) VALUES
(105,'R105','9:00-13:00',5);

SELECT * FROM room;


3. Queries to support enhancement of the interface to above function (Search)
In the software, We always have search engine bar to find the data we would like to return
back that data. And in here, There is a search bar in my User Interface to search students
name and major:
When we would like to search student name or major and return the information of this
student.

In here I want to search the information of student has last name “Nguyen” and return the
data have format: Student ID, Full Name, Major, Room ID, Subject Name, and status:
Syntax SQL:

SELECT s.studentId, s.fullname, s.major, r.roomId, sub.nameSubjects,


att.attendanceStatus
FROM students AS s
JOIN room AS r ON s.studentId = r.studentId
JOIN subjects AS sub ON s.studentId = sub.studentId
JOIN attendances AS att ON s.studentId = att.studentId
WHERE s.fullname LIKE '%Nguyen%';

The result will return student has last name is “Nguyen”:


After key “LIKE” is a string we want to find them for example, I want to find a student have
word “i” in their name in SQL:

SELECT s.studentId, s.fullname, s.major, r.roomId, sub.nameSubjects,


att.attendanceStatus
FROM students AS s
JOIN room AS r ON s.studentId = r.studentId
JOIN subjects AS sub ON s.studentId = sub.studentId
JOIN attendances AS att ON s.studentId = att.studentId
WHERE s.fullname LIKE '%i%';
The result has returned:
And I want to sort down some data have ‘a’ in their name:

SELECT s.studentId, s.fullname, s.major, r.roomId, sub.nameSubjects,


att.attendanceStatus
FROM students AS s
JOIN room AS r ON s.studentId = r.studentId
JOIN subjects AS sub ON s.studentId = sub.studentId
JOIN attendances AS att ON s.studentId = att.studentId
WHERE s.fullname LIKE '%a%' ORDER BY s.studentId DESC;
Result return in HeidiSQL:
III. Testing (P4)

No. Case Test Related object Desired result


1 Find a student Use the select Address, Return student
live in HCM syntax to find studentId, have address
the information fullname “TP.HCM”
in table.
2 Count all of Use count() and studentId, Return all
student have select to count attendanceStatus student
absented students were absent(0)
absent
3 Find all student Using Like ‘L%’ Fullname, Return all
have L in the first studentId, major student have “L”
name in their first
name
4 Find all student Using Join and Fullname, Return all
are studying where studentId, their student is
Networking major studying
Subject networking
5 Find all student is Using Join and Full name, Return all
studying at Room where student id, room student is
101 studying at Room
101
6 Find all student Using like Full name, Return all
study at 9:00 student id, time student study at
9:00
7 Find all student Using where Student id, full Return all
have been id > name student have id >
10 10
8 Join 4 table Using Join Student id, full Return all
name, subject student have
name, attendance new format
status Student id, full
name, subject
name,
attendance
status
Test case 1:
SELECT s.fullname,s.studentId, s.address
FROM students AS s
WHERE s.address LIKE '%TP.HCM%';
Result of test case 1:

Test case 2: All student have status = 0 will absent


SELECT COUNT(*) AS 'Absent day' FROM attendances AS att
WHERE att.attendanceStatus = 0;
Result of test case 2:

Test case 3:
SELECT s.studentId,s.fullname,s.major
FROM students AS s
WHERE s.fullname LIKE 'L%';
Result of test case 3:
Test case 4:
SELECT s.studentId,s.fullname, subjects.nameSubjects, s.major
FROM students AS s
JOIN subjects ON subjects.nameSubjects = 'Networking';
Result of test case 4:
Test case 5:
SELECT s.studentId,s.fullname, room.nameRoom
FROM students AS s
JOIN room ON room.nameRoom = 'R101';
Result of test case 5:
Test case 6:

SELECT DISTINCT s.studentId, s.fullname, r.time


FROM students AS s
JOIN room AS r ON r.time LIKE '9:00%';
Result of test case 6:
Test case 7:

SELECT DISTINCT s.studentId, s.fullname


FROM students AS s
WHERE s.studentId > 10
Result of test case 7:
Test case 8:

SELECT s.studentId, s.fullname, sub.nameSubjects, att.attendanceStatus,


r.nameRoom
FROM students AS s
JOIN subjects AS sub ON s.studentId = sub.studentId
JOIN attendances AS att ON s.studentId = att.studentId
JOIN room AS r ON r.studentId = s.studentId
Result of test case 8:
IV. Technical Document (P5)
1. Introduction
In this technical document, We are going to talk about how the system works simultaneously
with the blueprints that I have designed and slightly modified from the original design. This
document includes the ERD, ER design and future improvement of the system
2. ERD
ER design:

3. Possible and realistic improvements


This system currently works very well, although there have been upgrades and tweaks
that are different from some problems in the official design. In addition, the system may
not operate stably because it is being tested in the process of developing the database
system. because the time is not much to continue to develop further but can still meet the
needs of the present or most usefully a few years from now, in the future may change
some issues but at least the systems which I designed is the foundation that will never
change, just that in the future additions, there will be changes in some of the components
in it.
4. Date last changed and implemented
Date last changed and implemented: August – 26th – 2021

V. User Documents (P5)


1. Introduction
This is the application used to take attendance of students belonging to FPT University. To be
able to use it, you need to open the browser application by accessing ap.btec.edu.vn or open the
application called BTEC FPT on the screen or download it at the home page ap.btec.edu.vn. At
the interface screen you need to log in to be able to take attendance. To be able to take
attendance of students who are studying your subject and study in that classroom at any time,
you must be the one to teach that subject to students who are studying that subject. Also you
can add new students to the class you are teaching. In addition, you can edit information about
that student and remove that student from the class if that student violates the school's policy.
Besides, the attendance at the attendance screen will have some basic information of students
such as: Student ID, Full name, status including presence and absence, when attendance system
will fully save Full attendance information of that student including attendance time
2. The user interfaces
The screen for Add student:
The screen for update student:

The screen for delete student:


The screen for attendance

The screen for add, update and delete subject


3. Step by step how to achieve the functionality provided, for all paths though solution
Add new student:
You need to fill in the text the value you want to add and just follow the rules of that text
fill then you should click “Add” and data is going to insert in Database
For example I would like to insert new student in database have some basic information
and click button “Add new student”:

4. Data validation needed


Student name, room name, subject name, Major should be a string and less than 50
characters
Student id, subject id, attendance id, room id should be a numeric and more than 0
Start Date and end date are a date data type
The status in user interface attendance should be a integer 0 and 1 ( 0 is absent and 1 is
present )
References List

Celko, J., 2017. Validation, Verification, and Modification - Simple Talk. [ONLINE] Simple Talk. Available
at: https://www.red-gate.com/simple-talk/databases/sql-server/t-sql-programming-sql-
server/validation-verification-modification/. [Accessed 26 August 2021].

W3schools.com. n.d. SQL Keywords Reference. [ONLINE] Available at:


https://www.w3schools.com/sql/sql_ref_keywords.asp. [Accessed 26 August 2021].

W3schools.com. n.d. SQL INSERT INTO Statement. [ONLINE] Available at:


https://www.w3schools.com/sql/sql_insert.asp. [Accessed 26 August 2021].

W3schools.com. n.d. SQL UPDATE Statement. [ONLINE] Available at:


https://www.w3schools.com/sql/sql_update.asp. [Accessed 26 August 2021].

W3schools.com. n.d. SQL DELETE Statement. [ONLINE] Available at:


https://www.w3schools.com/sql/sql_delete.asp. [Accessed 26 August 2021].

W3schools.com. n.d. SQL LIKE Operator. [ONLINE] Available at:


https://www.w3schools.com/sql/sql_like.asp. [Accessed 26 August 2021].

W3schools.com. n.d. SQL Joins. [ONLINE] Available at: https://www.w3schools.com/sql/sql_join.asp.


[Accessed 26 August 2021].

W3schools.com. n.d. SQL PRIMARY KEY Constraint. [ONLINE] Available at:


https://www.w3schools.com/sql/sql_primarykey.asp. [Accessed 26 August 2021].

You might also like