Asm 2 SQL
Asm 2 SQL
In this Invoice we can see almost information related to customer and product such as: Name
of customer, address of customer, telephone of customer, name of the products, quantity,
price, purchase date or can be knows more information.
II. Problem:
As a programmer, I had to design a database for a company, namely designing a database with
evidence of user interface, output and data validations, and querying across multiple tables for
ElectroShop, one of the largest technology product sales companies in Vietnam.The purpose of
this database is to help the user, such as the manager can manage, statistics information
related to the customer, the number of products sold, the item which customers like and buy
the most, and also for the purpose of increasing sales productivity, increasing revenue for
ElectroShop and continue to make ElectroShop standing firmly in the business market of
technology products in Vietnam.
III. Criteria:
1.Database:
I created the database in order to help ElectroShop manage all information of customers and
products such as customer name, phone number or other information related to products such
as product name, price of the product. This database can also add, update and delete data,
which can help managers easily control the sales of the shop.
2.Function:
There are three basic functions: Add, Update and Delete data. It helps managers can be manage
information of ElectroShop.
+Add: Managers can add customer information or add product information.
+Update: Managers can easily change, update information if the information is wrong.
+Delete: Managers can remove one or more redundant or invalid information.
3.Security:
In order to ensure the security of the database, each client or manager has only one login
account and a unique password and password that is MD5-encrypted. This can limit the theft of
information and the loss of user data.
IV. Diagram Flow:
In order to better understand the purchase process of customers at ElectroShop, I have drawn a
diagram of the purchase activity at ElectroShop.
This image below is a diagram:
V. Mock up:
This image below shows four mock-up of four table I created base on requirement of customer:
We can see that each table contains all the information related to purchase invoices and each
table has three basic functions: Add, Update and Delete. In addition to have Login tables:
VI. Database Design:
1. Database normalization:
Data normalization is a technique for organizing data attributes so that they are grouped into
non-redundant, stable, flexible and adaptable entities:
• There is no iteration of attributes in different tables, except the key attribute and the
connection attribute.
• Does not contain values that are worth the calculated result of other attributes. For example,
the cost attribute is the result of the quantity attribute multiplied by the unit price attribute
and should be eliminated.
• There is no similar role between entities
Some common types of data normalization are:
-First Normal Form (1NF)
-Second Normal Form (2NF)
-Third Normal Form (3NF)
Customer Table
ORDER1 Table
Items Table
Order_Items Table
2.ER Diagram:
After reviewing the information from the invoice, I proceeded to design the database diagram. It
consists of four tables (ORDER1, Customer, Order_Items, Items).
The 1st: Customer tables, its have CustomerID (the customer buy anything on Tiki),
CustomerName, Address, City and Phone.
The 2nd: ORDER1 tables, it have OrderID, OrderDate(day customer buy product on Tiki),
customerID and PayMethods( Customer's payment method when buying products on Tiki).
The 3rd: Items table, it shows ItemID, ItemName, and Price.
The 4th : The next table is Order_Items table, it show three information: OrderID, ItemID and
Quantity.
The 5th : The Last table is Customer_Login table, it have three information CustomerID,Gmail
and Password
Explain:
Each invoice can have many products, many prices, but each invoice has only one code and one
customer can buy multiple products at the same time or there may be many customers with
the same name buy the same product but each the customer has only one unique ID, as well as
a single product code and each have only one Gmail account and one password.
3.Create Table:
Based on the normalization section above, I have to create 5 tables, include the Customers
table, ORDER1 table, Items table, Order_Items table, and Customer_Login table.
In order to create a table, we first have to use the database created using the command "USE
ASM1"
a. Create table customer:
I also use the same method as when creating the database to create the Customer table but
there is a difference in the command , instead of using the "CREATE DATABASE ASM1"
command, I use the "CREATE TABLE Customers" command (Enter the "CREATE TABLE
Customers" command then highlight the command and press Excute (or press the F5 shortcut))
to create the table.
The ORDER1 table creation method is similar to creating a Customer table, just replacing the
command “CREATE TABLE Customers” with command “CREATE TABLE ORDER1”
The ORDER1 table creation method is similar to creating a Customer table, just replacing the
command “CREATE TABLE Customers” with command “CREATE TABLE Items”
For the Items table, there are only three columns: ItemID, ItemName, Price with ItemID is
Primary Key.
d. Create Table Order_Items:
The next table is Order_Items table. The way to create table is almost the same as the table
above, just replace command “CREATE TABLE Customers” with the command “CREATE TABLE
Order_Items”.
The Order_Items table contains the columns OrderID, ItemID, Quantity. Special, OrderID,
ItemID have role is a foreign key that connects tables that have OrderID and ItemID as primary
keys (namely is connect ORDER1 table and Items table).
I use the statement "FOREIGN KEY (name of key) REFERENCES <name of table> (name of key)"
to refer to Primary Key from another table. And the statement "PRIMARY KEY (name of key)" is
used to create the Primary Key.
e. Create table Custumer_Login:
The last table is Customer_Login table. The way to create table is almost the same as the table
above, just replace command “CREATE TABLE Customers” with the command “CREATE TABLE
Customer_Login”.
4.Test Case:
Desc Input Expected Result Status
Insert
OrderDate=
11/22/2017
Result:
Result:
Result:
Result:
Result:
VII. Use:
After completing the database design, we conducted add some customer information from
the company, we determined the functionality of this database system with queries and results.
This image below shows ADD function:
Result:
We will update customer information if any information is wrong or store employees enter the
wrong data.
This image below show information in Customers Table before update data:
Customers Table
This image below show information after update:
Customers Table
We will delete purcharse product information if the customer want to cancel the
purcharse.This image below illustrate funtion delete:
Order_Items Table
Invoices Information
VIII. Evaluation:
After completing the database design based on customer requirements, I conducted a review of
the benefits and disadvantages to find good solutions to this database system.Here are some
advantages and disadvantages.
1.Advantages:
- User information security: Each user has only one account and one password. Customer
passwords are MD5-encrypted, which helps to prevent data theft and user data loss.
This image below how the encrypted password after entering the password 123456.
Result:
- With the storage of a large amount of information that ElectroShop products business users
just need to find the website or application of ElectroShop to find the product that you want
and order and process the rest ElectroShop will be responsible, this is very convenient and save
time for ElectroShop customers.
- For the manager they can easily control the user information also the product information
through the application we design, they can easily add new product information ,add picture of
product, add user information, add picture of customers, update information, delete the wrong
information.
This image below show some function :
Result:
Delete Function
Result:
Update Function
- Because the database has been standardized by 3NF, there is no duplication of data that will
make it easier for managers to statistically and analyze data.
-Customers can login to the system to check personal information or check the purchase
history. Customers can login by email or telephone number. If the customer forgot the
password, then click on "Forgot Password " and they can also sign in other ways such as login
by Facebook, login with Google account or Twitter account, it is very convenient if user does
not register for ElectroShop account.
- Because the test case has been identified, it is possible to identify instances where the user
entered incorrectly or entered missing data, thus limiting at least the errors when the user use
the database system to store data.
2.Disadvantages:
In addition to the benefits that database systems bring to the user, there are some limitations
that need to be addressed:
- MD5 security is still not the best security type for this database, others can still steal user
information. can use Bcrypt encryption, because Bcrypt encryption is safer than MD5, but users
will have to pay additional costs.
This image below shows 1 solution to steal information:
- Because we use Microsoft SQL Server as a database for ElectroShop, so it will take up a lot
of
computer memory, long-term use will cause slowdown of the device. To limit this situation just
need upgrade hardware and more RAM to make computer run smoother.