This exercise scores Distinction in database programming. This exercise demonstrates how to code a database, database query syntax, and ways to normalize data while developing a system in Microsoft SQL.
Trang 1ASSIGNMENT 2 FRONT SHEET
Unit number and title Unit 04: Database Design & Development
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
Trang 2 Summative Feedback: Resubmission Feedback:
Signature & Date:
2.1
2.2
Trang 3Table of Contents
A Introduction 9
B Task 1: Develop the database system 9
1.1 Final Mock-up of the application 9
1.2 Queries to create database with results 26
1.3 Database maintenance features and system security 34
a Maintenance features 35
b System security 35
C Task 2: Produce queries 37
2.1 Queries to INSERT data with illustrations of final result 37
2.2 Queries to UPDATE data with illustrations of final result 42
2.3 Queries to DELETE data with illustrations of final result 42
2.4 Queries to SELECT data with illustrations of final result 44
2.5 Advanced queries: Stored procedures, triggers, functions 47
a Stored Procedures 47
b Triggers 49
DML triggers 50
DDL triggers 52
c Functions 53
2.6 Evaluate the effectiveness of the database solution and improvements 54
a Effectiveness of database solution 54
b Improvements 56
Trang 4D Task 3: Test the system 57
3.1 Test cases 57
a Test plan and test result 57
b Overall evaluation of testing part 61
3.2 Flowchart to show how the system works 61
a System flowchart 61
b Insert information flowchart 63
c Update information flowchart 64
d Delete information flowchart 65
3.3 Produce technical and user documentation 66
3.3.1 Produce technical 66
a Introduction 66
b ERD 66
3.3.2 User documentation 68
3.4 Evaluate any future improvements to ensure the continued effectiveness of the database system 77
a Scalability 77
b Security 77
c Monitor performance 78
d Data backup 80
e User interface and usability 81
f Integration with other systems 81
E Conclusion 86
Trang 5Table of Figures
Figure 1: Login interface 10
Figure 2: Register interface 11
Figure 3: Main layout 12
Figure 4: Menu of view option 13
Figure 5: View Customer List Layout 14
Figure 6: View Staff List Layout 15
Figure 7: View order list layout 16
Figure 8: View Product List Layout 17
Figure 9: Menu of add options 18
Figure 10: Add new Staff layout 19
Figure 11: Add New Customer Layout 20
Figure 12: Add new Order Layout 21
Figure 13: Add New Product Layout 22
Figure 14: Menu of Update options 23
Figure 15: Update Customer layout 24
Figure 16: Menu of Statistic options 25
Figure 17: Create Database of system 26
Figure 18: Create schemas of system 26
Figure 19: Create Brands table 26
Figure 20: Create Categories table 27
Figure 21: create Products table 27
Figure 22: Create Discounts table 28
Figure 23: Create Customers table 28
Figure 24: Create Staffs table 29
Figure 25: Create orders table 29
Figure 26: Create OrderItems table 30
Figure 27: Result of creating table 31
Figure 28: Table Brands 31
Figure 29: Table Categories 31
Trang 6Figure 30: Table Products 31
Figure 31: Table Discounts 32
Figure 32: Table Customers 32
Figure 33: Table Staffs 33
Figure 34: Table Orders 33
Figure 35: Table OrderItems 33
Figure 36: Final diagram 34
Figure 37: Create user login of system and result 35
Figure 38: Queries to create roles Manager and Staff to access 36
Figure 39: Role access of Staff 36
Figure 40: Role access Manager 37
Figure 41: Queries to insert table Brands and result 38
Figure 42: Queries to insert table Categories and result 38
Figure 43: Queries to insert table Products and result 39
Figure 44: Queries to insert table Customer and result 39
Figure 45: Queries to insert table Discount and result 40
Figure 46: Queries to insert table Staffs and result 40
Figure 47: Queries to insert table Orders and result 41
Figure 48: Queries to insert table OrderItems and result 41
Figure 49: Data before update 42
Figure 50: Queries to update data 42
Figure 51: Data after update 42
Figure 52: Data before delete 43
Figure 53: Queries to delete 43
Figure 54: Data after delete 43
Figure 55: Queries to staff's information and result 44
Figure 56: Queries to Customer's information and result 44
Figure 57: Queries to Order's information and result 45
Figure 58: Queries to all Discount code and result 45
Figure 59: Queries to product's information and result 46
Trang 7Figure 60: Queries to items of order and result 46
Figure 61: Queries top 5 the good staffs last year and result 47
Figure 62: Queries to top 5 most purchased customer last year and result 48
Figure 63: Queries to top 5 most popular produtcs 49
Figure 64: Create table to contain change customer's information 50
Figure 65: DML trigger to monitor insert, update delete actions of Customer 51
Figure 66: Test and result of DML trigger 51
Figure 67: create table to contain change customer's information 52
Figure 68: create DDL trigger to display in ChangeLogs table 52
Figure 69: Test and result of DDL trigger 53
Figure 70: Create function fn_FindManageInfo to find the number of staffs each manager holds 54
Figure 71: Result function 54
Figure 72: Create index to improve system 56
Figure 73: Test index 57
Figure 74: Flowchart of system 62
Figure 75: Flowchart add information in tables 63
Figure 76: Flowchart update information in tables 64
Figure 77: Flowchart delete information in tables 65
Figure 78: ER diagram 67
Figure 79: User doc 01 68
Figure 80: User doc 02 69
Figure 81: User doc 03 70
Figure 82: User doc 04 71
Figure 83: User doc 05 72
Figure 84: User doc 06 73
Figure 85: User doc 07 74
Figure 86: User doc 08 75
Figure 87: User doc 08 76
Figure 88: Use firewall to security 77
Figure 89: SQL Server profiler 78
Trang 8Figure 90: Connect SQL Server Profiler 79
Figure 91: Fill information trace 79
Figure 92: Event trace 80
Figure 93: Back up my data 80
Figure 94: Back up data of this system 81
Figure 95: Connect this database with visual studio 82
Figure 96: Connect data successfully 83
Figure 97: Query data product by C# 85
Figure 98: Result data of product in console application 86
Trang 9A Introduction
In this assignment, an online shop system database was implemented on SQL server using query language This database offers, permits changing, removing, and entering important information to manage the shop such as customer and staff personal information, login, product information, and discount code It is also equipped with data to assist administrators in managing and monitoring the store's status A comprehensive mock-up, as well as a relational database, has been
developed and exhibited here Bugs are also fixed by testing Lastly, a technical database was created to assist users in utilizing this system based on the mock-up
B Task 1: Develop the database system
1.1 Final Mock-up of the application
In the first report, I thoroughly examined the FPT shop's users and features A comprehensive blueprint of the system was created based on the existing mock-up designs from the previous assignment In order to design and enhance the system, I created a user interface in this report that combines the system's functionalities The FPT shop system interfaces are as follows:
• The first is the system's login interface, which includes a login and sign-up button:
Trang 10Figure 1: Login interface
Trang 11• The next is register interface:
Figure 2: Register interface
Trang 12• The main interface of the system, including 4 main functions view, add, update, and statistics
Figure 3: Main layout
Trang 13• When the user clicks the view button, the following UI appears Items related to Staff information, Product information, Order information, Customer information, and so on will be shown, with users able to inspect information by clicking on the option
Figure 4: Menu of view option
Trang 14• When the user selects Customer List, the interface will appear like this
Figure 5: View Customer List Layout
Trang 15• When the user selects Staff List, the interface will appear like this
Figure 6: View Staff List Layout
Trang 16• The same is true of the Product List and Order List By hitting the Back button on each interface, the user will be able to return to the previous screen
Figure 7: View order list layout
Trang 17Figure 8: View Product List Layout
Trang 18• This is the UI that shows when the user clicks the Add button Users can input relevant information by clicking on options Items that lead to more information about the Staff, Customers, products, and so on will be shown
Figure 9: Menu of add options
Trang 19• When the user hits Add Staff, the required information will be displayed After entering the necessary information, the user will click the Add button to complete the task
Figure 10: Add new Staff layout
Trang 20• Customer, Product, Order are all examples of information that may be added
Figure 11: Add New Customer Layout
Trang 21Figure 12: Add new Order Layout
Trang 22Figure 13: Add New Product Layout
Trang 23• When the user clicks the Update button, the following UI appears Items related to Staff information, Product information, Order information, Customer information, to edit information by clicking on the option
Figure 14: Menu of Update options
Trang 24• When the user hits Update Customer, the required information will be displayed After entering the necessary information, the user will click the Update button to complete the task Cases like Staffs, Order, Product are similar
Figure 15: Update Customer layout
Trang 25• This is the UI that shows when the user clicks the Stats button The statistics and other actions of the system will
be shown Users can choose View or Update for new updates
Figure 16: Menu of Statistic options
Trang 261.2 Queries to create database with results
The query that builds the table will establish a database system based on the designs authorized by the CEO The database is created as the first stage in constructing the system
The database is created as the first stage in constructing the system I use Create Table statement to create table of system
Figure 17: Create Database of system
I'll design two schemas, sales and production, to partition the system into two distinct levels
Figure 18: Create schemas of system
Next to, as shown in the design, we must construct the data tables
Figure 19: Create Brands table
Trang 27Figure 20: Create Categories table
Figure 21: create Products table
Trang 28Figure 22: Create Discounts table
Figure 23: Create Customers table
Trang 29Figure 24: Create Staffs table
Figure 25: Create orders table
Trang 30Figure 26: Create OrderItems table
The primary and foreign key constraints have been appropriately named, along with the unique constraint I use
update/delete cascade to show the relationship between parent-child tables This mean that allow to delete or update rows
in the child table corresponding to the deleted or updated row in the parent table The following is the results of the newly created tables:
Trang 31Figure 27: Result of creating table
Figure 28: Table Brands
Figure 29: Table Categories
Figure 30: Table Products
Trang 32Figure 31: Table Discounts
Figure 32: Table Customers
Trang 33Figure 33: Table Staffs
Figure 34: Table Orders
Figure 35: Table OrderItems
Trang 34Figure 36: Final diagram
1.3 Database maintenance features and system security
Trang 35b System security
o For this part, I will create 2 users: Staff and Manager to assign access rights to the system
Figure 37: Create user login of system and result
o Next, I will assign user permissions Each manager can access the system to read statistics as well as perform insert, update, select, and delete operations in the tables Employees only have access to the orders table and Customers table to insert and select Employees do not have the right to delete information in these tables
Trang 36Figure 38: Queries to create roles Manager and Staff to access
The login account has the role of Member, so it only has permissions in the orders and customers table.
Figure 39: Role access of Staff
Trang 37The login account has the role of Manager, so it only has permissions in all tables.
Figure 40: Role access Manager
C Task 2: Produce queries
2.1 Queries to INSERT data with illustrations of final result
Following the construction of the tables, we will enter the initial data information into the tables I use insert into statement
to insert data as follows:
Trang 38Figure 41: Queries to insert table Brands and result
Figure 42: Queries to insert table Categories and result
Trang 39Figure 43: Queries to insert table Products and result
Figure 44: Queries to insert table Customer and result
Trang 40Figure 45: Queries to insert table Discount and result
Figure 46: Queries to insert table Staffs and result
Trang 41Figure 47: Queries to insert table Orders and result
Figure 48: Queries to insert table OrderItems and result
Trang 422.2 Queries to UPDATE data with illustrations of final result
If any information is incorrect or has to be corrected throughout the data entry process, I will use the Update statement to fix data it
Example: Admin wants to edit customer's information of PhoneNumber = 0974123452 with new information in name, email, etc I use the query as the following:
Figure 51: Data after update
2.3 Queries to DELETE data with illustrations of final result
If an Admin decides to quit or the FPT store wishes to remove a Product from the menu during the administration process,
the system has the ability to delete that data using the Delete statement
Example: Manager want to delete information of ProductId = 2, I use the query as following:
Trang 442.4 Queries to SELECT data with illustrations of final result
The first step is to query the employee's information I use the select from statement, in this query I use the self-join type to allow the Staffs table to connect to itself
Figure 55: Queries to staff's information and result
Then is to query the employee's information following as:
Figure 56: Queries to Customer's information and result
Trang 45To query information about orders, I use type inner join to connect 3 tables Orders, Customers and Staffs together, order by command is used to sort information by latest creation date
Figure 57: Queries to Order's information and result Next is the query for discount codes:
Figure 58: Queries to all Discount code and result
Trang 46To query information about products, I use type inner join to connect 3 tables Products, Brands and Categories together
Figure 59: Queries to product's information and result
To query information about orders, I use type inner join to connect 3 tables OrderItems, Products and Discounts together, I will use function sum to calculate total and the group by clause to group the data, order by to sort information total payment
Figure 60: Queries to items of order and result