






























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!































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
1. Assignment Brief 2 (RQF)
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:
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
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
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
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