Docsity

Database System Development and Testing: A Practical Guide with SQL Server, Assignments of Database Programming

Partial preview of the text

Download Database System Development and Testing: A Practical Guide with SQL Server and more Assignments Database Programming in PDF only on Docsity!

Higher Nationals in Computing

Database Design and

Development

ASSIGNMENT

No. 2

Learner’s name:

Assessor name: NGUYEN VAN SON

Class:

Learner’s ID:

Subject’s ID: 1622 (Database Design & Development)

Assignment due: Assignment submitted:

ASSIGNMENT 2 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 Student ID Class Assessor name Nguyen Van Son 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 D

1. Assignment Brief 2 (RQF)

1.1 Higher National Certificate/Diploma in Computing

Student Name/ID Number: Unit Number and Title: Unit 04: Database Design & Development Academic Year: 2022 Unit Assessor: Nguyen Van Son Assignment Title: Database implementation and Testing Issue Date: 15 /10/ Submission Date: Internal Verifier Name: Date: Submission Format: Format:

  • This assignment is an Individual assignment and specifically including 2 documents: (1) sql file of your code and represent your code to your tutor (2) a report document
  • You must use font Calibri size 12, set number of the pages and use multiple line spacing at 1.3. Margins must be: left: 1.25 cm; right: 1 cm; top: 1 cm and bottom: 1 cm. The reference follows Harvard referencing system. The recommended word limit is 2.000-2.500 words. You will not be penalized for exceeding the total word limit. The cover page of the report has to be the Assignment front sheet 2. Submission
  • Students are compulsory to submit the assignment in due date and in a way requested by the Tutor.
  • The form of submission will be a soft copy posted on http://cms.greenwich.edu.vn/.
  • Remember to convert the word file into PDF file before the submission on CMS. Note:
  • The individual Assignment must be your own work, and not copied by or from another student.
  • If you use ideas, quotes or data (such as diagrams) from books, journals or other sources, you must reference your sources, using the Harvard style.
  • Make sure that you understand and follow the guidelines to avoid plagiarism. Failure to comply this requirement will result in a failed assignment. Unit Learning Outcomes: 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 Assignment Brief and Guidance: Assignment scenario You are employed as a Database Developer for a large IT consultancy company. The company has been approached by FPT Shop which is expanding due to the growth of the number of stores. FPT Shop is currently facing difficulties in dealing with managing the database from all shops on over country. It decided to develop a new database so that: users can register with their phone numbers as IDs and order or rate, comment for their bought devices, shop managers can take care for their stores and director board can view all data from all shops. You are tasked to select one of those systems to develop database for FPT Shop. Your tasks are to:
  • Work with FPT Shop to find out about current requirements for each system
  • Analyse the requirements and produce clear statements of user and system requirements.
  • Design a relational database system using appropriate design tools and techniques
  • Develop a fully functional relational database system, based on an existing system design.
  • Test the system against user and system requirements.
  • Produce technical and user documentation Part 2 (Assignment 2) Once the designs have been accepted by your manager you have been asked to: Develop the database system using evidence of user interface, output and data validations and querying across multiple tables. You want to include more than just the basics so you will implement a fully functional database system which will include system security and database maintenance features. You have decided to implement a query language into the relational database system. The developed system will be demonstrated to your manager. Your manager has asked you to include in the report: (1) Assessing whether meaningful data has been extracted through the use of query tools to produce appropriate management information. (2) Evaluating the effectiveness of the database solution in relation to user and system requirements, and suggest improvements.

Table of Contents

ASSIGNMENT 2 ANSWERS ....................................................................................................................................... 9

P2 Develop the database system with evidence of user interface, output and data validations, and querying across multiple tables.............................................................................................................................. 9 Chapter 1 - Develop the database system ........................................................................................ 9

  1. Itroduction............................................................................................................................... 9 What is Microsoft SQL Server? ..................................................................................................... 9 1.1 Final Mock-up of the application. ......................................................................................... 10 1.2 Queries to create database with results................................................................................ 10 Data validation .......................................................................................................................... 16 P3 Implement a query language into the relational database system. ......................................................... 18 Chapter 2 – Produce queries.......................................................................................................... 18 2.1 Queries to INSERT data with illustrations of final result. ....................................................... 18 2.2 Queries to UPDATE data with illustrations of final result....................................................... 23 2 .3 Queries to DELETE data with illustrations of final result. ....................................................... 24 2.4 Queries to SELECT data with illustrations of final result. ....................................................... 25 P4 Test the system against user and system requirements. ........................................................................... 30 Chapter 3 – Test the system .......................................................................................................... 30 3.1 Test cases............................................................................................................................. 30 a. Test Plan. ............................................................................................................................... 30 b. Test Result. ............................................................................................................................ 30 REFERENCES .................................................................................................................................. 36

List of Figures

Figure 1: Microsoft SQL Server Figure 2: ER Diagram Figure 3: Create database FPT shop Figure 4: Create table category Figure 5: Category Table Figure 6: Create Product Table Figure 7: Product Table Figure 8: Create Staff Table Figure 9: Staff Table

Figure 10: Create Customer Table Figure 11: Customer Table Figure 12: Create Order Table Figure 13: Order Table Figure 14: Create Order Detail Table Figure 15: Order Detail Table Figure 16: Result of creating table Figure 17: Final database diagram Figure 18: Example of INT data type Figure 19: Example of NVARCHAR data type Figure 20: Example of DATE data type Figure 21: Example of CHAR data type Figure 22: Example of BIT data type Figure 23: Example of CONSTRAINT data type Figure 24: Example for CASCADE UPDATE Figure 25: Example for Cascade DELETE Figure 26: Insert data for Category table Figure 27: Results Insert data for Category table Figure 28: Insert data for Product table Figure 29: Results Insert data for Product table Figure 30: Insert data for Customer table Figure 31: Results Insert data for Customer table Figure 32: Insert data for Staff table Figure 33: Results Insert data for Staff table Figure 34: Insert data for Order table Figure 35: Results Insert data for Order table Figure 36: Insert data for Order Detail table Figure 37: Results Insert data for Order Detail table Figure 38: Query to UPDATE

ASSIGNMENT 2 ANSWERS

P2 Develop the database system with evidence of user interface, output and data

validations, and querying across multiple tables.

Chapter 1 - Develop the database system

  1. Itroduction In the previous report, I did a deep understanding of the users and designed the necessary features of the FPT shop system. To build a complete and consistent system, I created a user interface that incorporates the system's functions in this report. And the software that I will use to develop the system is Microsoft SQL Server. What is Microsoft SQL Server? Microsoft SQL Server is a relational database management system that supports a variety of transaction processing, business intelligence, and analytics applications in corporate IT environments. Microsoft SQL Server is one of the top three database technologies on the market. Microsoft SQL Server is built on top of SQL, a standardized programming language that database administrators and other IT professionals use to manage databases, data, and data queries. they contain. Figure 1: Microsoft SQL Server

1.1 Final Mock-up of the application. A mockup (or mock-up) is a miniature model, an image that simulates a design. A mockup is a prototype so that we can test the design, and add and provide the necessary functionality to the system. Figure 2: ER Diagram 1.2 Queries to create database with results. To build a database system, a database must be created in SQL Server, FPT shop is the database created and used to store in this system. Tables will be created by queries so that data types and data validation are designed. "CREATE DATABASE" + "name of database" is the command to be able to create a database. And the command "use database" to be able to choose the database to use.

This query is to create the Product Table. "Create a table" + "Product" where the data is the Product ID and the Product Name, Product Type, Product Items, Category ID, and Price. With “Product ID” as the primary key and "Category ID" references from Category Table as a foreign key in the table. Figure 6: Create Product Table Here is the result after using CREATE statement to create a Product Table. Figure 7: Product Table

This query is to create the Staff Table. "Create a table" + "Staff" where the data is the Staff ID and the Staff Name, Staff Phone, and Staff Mail. With “Staff ID” as the primary key in the table. Figure 8: Create Staff Table Here is the result after using CREATE statement to create a Staff Table. Figure 9: Staff Table This query is to create the Customer Table. "Create a table" + "Customer" where the data is the Customer ID and the Customer Name, Customer Sex, Customer Address, Customer Phone, and Date of Birth. With “Customer ID” as the primary key in the table. Figure 10: Create Customer Table

This query is to create the Order Detail table. "Create a table" + "Order Detail" where the data is the Order ID, the Product ID, and the Amount. With "Order ID" references from Order Table as a foreign key and "Product ID" references from Product Table as a foreign key in the table. Figure 14: Create Order Detail Table Here is the result after using CREATE statement to create a Order Detail Table. Figure 15: Order Detail Table The foreign key and primary key of the table are generated during construction and the following result is: Figure 16: Result of creating table

Final database diagram Figure 17: Final database diagram The primary keys of the tables are unique. A foreign key is a relationship between two tables and the relationship we call parent-child, that is, if table a has an attribute associated with table b, then table b is the parent role, and table a is the child. Having 5 primary keys from 6 tables gives the uniqueness of that table. Those primary keys are the ids of the tables Category ID, Product ID, Customer ID, Staff ID, and Order ID. There are 5 primary keys in the database: Category ID is the primary key of the Category table and the secondary key of the Product table, the Product ID is the primary key of the Product table and Order Detail subkey, the Order ID is the primary key of Order table and is Order Detail subkey. And Staff ID is the primary key of the Staff table. Customer ID is the primary key of the Customer table. Data validation

CASCADE UPDATE: When we use this option to set up a foreign key, it deletes referrer rows in the child table when a referred row in the father table with the primary key is dropped. Figure 24: Example for CASCADE UPDATE CASCADE DELETE: When we use UPDATE CASCADE to generate a foreign key, the reference rows in the child table are updated when the row is introduced in the parent table whose primary key is modified. For example, consider the Item Categories table and its subtable, the Items table. The foreign key connects the Item Category ID column in the Item Categories table to the Item Category ID column in the Item table. Figure 25: Example for Cascade DELETE

P3 Implement a query language into the relational database system.

Chapter 2 – Produce queries

2.1 Queries to INSERT data with illustrations of final result. Insert into "table name" values (value1, value2, value3, value4) is the syntax to be able to add information to the table. Where "table name" is the table name to add data and the "values" are the input data of the table. The values will be arranged in the corresponding vertical columns from left to right. We will input the first data information into the tables after the tables have been constructed as follows:

This query is to insert data into the Category table. Insert into “Category” + “values” Figure 26 : Insert data for Category table Results after inserting into the Category table. Figure 27 : Results Insert data for Category table This query is to insert data into the Product table. Insert into “Product” + “values” Figure 28 : Insert data for Product table