Docsity

Database Design and Implementation: A Practical Guide with SQL Server - Prof. DATABASE DES, Essays (university) of Database Programming

Toggle sidebar
bg1
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
Le Minh Hoang
Student ID
GCH210529
Class
GCH1101
Assessor name
Lecture Manh
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
hoang
Grading grid
P3
P4
P5
M2
M3
M4
M5
D2
D3
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download Database Design and Implementation: A Practical Guide with SQL Server - Prof. DATABASE DES and more Essays (university) Database Programming in PDF only on Docsity!

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 Le Minh Hoang Student ID GCH

Class GCH1101^ Assessor name Lecture^ Manh

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 hoang

Grading grid

P2 P3 P4 P5 M2 M3 M4 M5 D2 D

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:

Signature & Date:

I. Develop the database system

1. Final Mock-up of the application

  • Table diagram
  • Each table can have only one primary key. Foreign Key will help us to link two tables together. A table

can have many Foreign Keys

  • There are 6 main keywords corresponding to 6 different tables. The main key that is ID of the table Customer, Feedback, Producer, Ỏders, Items, ItemDetail
  • User interfaces

 Feedback

 Producer

 Orders

 Customer

2. Queries to create database with results

Database named Lmh

Creat databese

CREATE DATABASE [Lmh] CONTAINMENT = NONE ON PRIMARY ( NAME = N'Lmh', FILENAME = N'E:\SQL server\MSSQL14.SQLEXPRESS\MSSQL\DATA\Lmh.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB ) LOG ON ( NAME = N'Lmh_log', FILENAME = N'E:\SQL server\MSSQL14.SQLEXPRESS\MSSQL\DATA\Lmh_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB ) GO

o Result

Customers table

CREATE TABLE [dbo].[Customers]( [CustomerID] [int] NOT NULL, [CustomerFirstName] nvarchar NOT NULL, [CustomerLastName] nvarchar NULL, [CustomerAddress] nvarchar NOT NULL, [CustomerPassword] nvarchar NOT NULL, CONSTRAINT [PK_Customers] PRIMARY KEY CLUSTERED ( [CustomerID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO

o Result

Items table

CREATE TABLE [dbo].[Items]( [itemID] [int] NOT NULL, [itemName] nvarchar NOT NULL, [ProducerID] [int] NOT NULL, [ItemDetail_ID] [int] NOT NULL, CONSTRAINT [PK_Items] PRIMARY KEY CLUSTERED ( [itemID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO

o Result

Item detail table

CREATE TABLE [dbo].[ItemDetail]( [ItemDetail_ID] [int] NOT NULL, [ItemNote] nvarchar NULL, [ItemPrice] [int] NOT NULL, CONSTRAINT [PK_ItemDetail] PRIMARY KEY CLUSTERED ( [ItemDetail_ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO

o Result

Feedback table

CREATE TABLE [dbo].[Feedback]( [FeedbackID] [int] NOT NULL, [Feedback_Detail] nvarchar NULL, [CustomerID] [int] NOT NULL, [itemID] [int] NOT NULL, CONSTRAINT [PK_Feedback] PRIMARY KEY CLUSTERED ( [FeedbackID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO

o Result

II. Produce queries

1. Queries to INSERT data with illustrations of final result

Customers

INSERT INTO [dbo].[Customers] ([CustomerID] ,[CustomerFirstName] ,[CustomerLastName] ,[CustomerAddress] ,[CustomerPassword] ) VALUES ('105','Hoang','Phong','Hai Phong','555')

o Result

Item Detail

INSERT INTO [dbo].[ItemDetail] ([ItemDetail_ID] ,[ItemNote] ,[ItemPrice]) VALUES ('4','oke','1200')

o Result

Feedback

INSERT INTO [dbo].[Feedback] ([FeedbackID] ,[Feedback_Detail] ,[CustomerID] ,[itemID]) VALUES ('4','Good standards','104','4')

o Result

Orders

INSERT INTO [dbo].[Orders] ([OrderID] ,[Order_item] ,[Order_quantity] ,[Order_price] ,[Order_total] ,[itemID] ,[CustomerID]) VALUES ('1','iphone14','1','1000','1000','1','101')

o Result

2. Queries to UPDATE data with illustrations of final result

This is a simple update statement with the table name and the information of a column in the table. In the above example, updating the Feedback table with Feedback_ID = 1 will update the Detail of the Feedback with that ID number 1 to 'This product good enough for me”.

 Before

 After

 Querry data in Customer Table

 Querry data in ItemDetail Table

 Querry data in Producer Table

5. Advanced queries: Stored procedures, triggers, functions

A trigger is a stored procedure in database which automatically invokes whenever a special event in the database occurs. For example, a trigger can be invoked when a row is inserted into a specified table or when certain table columns are being updated. Suppose, an application needs to insert new members, then the data should be stored in a table called "customer_approvals” so that it can be approved before inserting into the "customer" table. First, we need to create a view named “view_customer” to insert new customer. Customer inserted into the view will be triggered to insert Customer into the “customer_approvals” table by a "trigger". Below are the specific images.

  • Statement to create a table named “customer_approvals” to store products pending approval
  • Next is to create a view with the name is “view_customer” based on the table customer and the table “customer_approval”
  • When a record is inserted into the VIEW "view_customer", "view_customert" needs to go to the table "customer_approvals" via "trigger instead of" through the following commands.
  • The trigger inserts a new member into the "customer_approvals" table if the member id does not exist in the "Customers" table. To make it clear, insert a new member with id = 7 and id = 8 into the VIEW "view_customer".
  • The INSERT statement will trigger "TRIGGER INSTEAD OF" to insert a new record into the

"customer_approvals" table. Query data from VIEW "view_customer" then new records will appeal

6. Evaluate the effectiveness of the database solution

Due to their underuse, a number of sophisticated functions have not been properly

employed in the essay. Performance of my database solution is essentially usable. The

implementation phase was fraught with difficulties and system malfunctions. the use of

SQL

After the subject's lecturers' intense coaching, server became simpler. For a deeper

understanding of SQL Server and the database, we'll continuing studying more complex

ideas. Looking forward to adding data to mock-ups made in other computer languages in

the future