You are on page 1of 20

Imam Mohammad Ibn Saud Islamic University

College of Computer and Information Sciences


Information Systems Department
Project
Course Title: Introduction to Databases
Course Code: IS 220
Course Instructor: Female: Dr. Hala Alrumaih
Male: Dr. Yasser Kotb
Semester: Spring 2022
Due Date: 22-05-2022

Instructions:
1. Submission date is on 18-04-2022 via IMAMU LMS Blackboard before 10 a.m.
2. Any attempt to cheat from any of your classmates or form the Internet the whole
assignment/project will be marked as Zero. Be aware that Blackboard uses
plagiarism check tool! (Read and sign Plagiarism Declaration)
3. There will be no extension in the submission deadline.
4. No hand writing is accepted.
5. Use this cover page.

Project Title Amazon company


Section No. 171 Group No.

Read and
Students accept
Students Names Mark out of 15
IDs (Plagiarism
Declaration)
Mohammed Fheed
440017803
Alhassan

Plagiarism Declaration: I declare that the proposed document is my own


work and I own the copy right of it with no copy rights violation or
plagiarism from other resources

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
Project Evaluation's Sheet
Deserved Criteria's
Criteria
Points Points
Part # 1: Conceptual Part 3
● Short description (about one paragraph) of the database
0.5
application
● Clear data requirement that describes the entities (7) 0.5
● EER (Entities, Relationship, Attributes, Cardinality,
2
Multiplicity)
Part # 2: Logical part 3
● Map EER model to a relational database schema 2
● Normalize your schema to the third normal form 1
Part # 3: Physical Part (implementation) 6
Schema Implementation 2.5
● Use appropriate naming conventions for all of your tables
0.5
and attributes
● SQL DDL statements to create database, primary key and
0.5
foreign keys must be defined
● Define attributes, data types, constraints e.g. NOT
0.5
NULL/UNIQUE
● Explain where and how referential integrity constraints have
0.5
been incorporated
● Insert at least 5 rows into each table 0.5
Query implementations 3.5
● 2 different update queries 0.5
● 2 different delete queries 0.5
● 2 simple select queries related to your tables 0.5
● 2 nested queries related to your tables 0.5
● 2 simple join queries related to your tables 0.5
● 2 simple retrieval queries using group by, having clause, and
0.5
aggregation functions related to your tables
● 2 different views, give SQL translations of them, and
0.5
indicate their implementation and solutions
Report format and overall adherence 1
● Report format 0.5
● Project run and overall adherence to project specification. 0.5
Subtotal#1 (CLO 2.4) 13

Presentation 2
● Slides (CLO 3.2) 1
● Discussion (CLO 3.1) 1
Subtotal#2 2

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
Answers

Part # 1: Conceptual Part

Our client is Amazon E-commerce, which is an online based E-commerce platform. It


sells books, music, households, electronics and many other products and services.
Below ERD provides the database details of Amazon E-commerce and this ERD will
elaborate the associated important entities and attributes of the scenario.

Entities and corresponding attributes


1. Product - Used to store the product data.
a. Attributes - product_id(PK), product_name, summary, qty, discount,
user_id(FK), category_id(FK).

2. Category – Used to store the category of products.


a. Attributes - category_id(PK), content, category_name, user_id(FK)

3. Order – Used to store the orders from customers.


a. Attributes - order_id(PK), status, created_date, shipping_address,
shipping_charge, discount, subtotal, grand_total, cart_id(FK),
user_id(FK)

4. Payment – Used to store the billing and payments of orders.


a. Attributes - payment_id(PK), payment_type, payment_date,
user_id(FK), order_id(FK)

5. User – Used to store user information including admins, customers and


vendors.
a. Attributes - user_id(PK), username, password, admin, vendor,
first_name, last_name, address, email, mobile_num

6. Cart – Used to store the products being selected by the customers.


a. Attributes - cart_id(PK), num_of_products, subtotal, user_id(FK)

7. Product_Review – Used to store the review of the products.


a. Attributes - review_id(PK), date, comment, rating, user_id(FK),
product_id(FK)

8. Shipping – Used to store the shipment details of the order made by the
customer.
a. Attributes - shipping_id(PK), shipping_address, status, agent_id(FK),
order_id(FK)

9. Agent – Used to store the agent details associated with shipment.


a. Attributes – agent_id(PK), agent_name, address, contact_num

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
 Customer can have zero or multiple orders as well as carts. Order or Cart can
have one user.
 Customer can write zero or more reviews. A review can be written by one
customer.
 Vendor can add more than product. Also, a product can be many vendors
 An admin can add one or more category. A category can be add by one admin.
 An agent can have multiple shippings. A shipping can have only one agent.
 An order can have one shipping and a shipping can contain multiple orders.
 An order can have only cart as well as a cart can have one order.
 A payment can be made for one order and order can have only one payment.
 A product can have zero or many reviews and one review can be given for one
product.
 Category can have many products and one product will be available under one
category.

Part # 2: Logical part

Note: Normalization is not required to below diagram, since all the entities have
primary key which can be used to uniquely identify each row.

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
Part # 3: Physical Part (implementation)

We created the table using Xampp MySQL.

Create Table ‘agent’

Create Table ‘cart’

Create Table ‘category’

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
Create Table ‘order’

Create Table ‘payment’

Create Table ‘product’

Create Table ‘product_review’

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
Create Table ‘shipping’

Create Table ‘user’

Alter Table ‘cart’

Alter Table ‘agent’

Alter Table ‘category’

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
Alter Table ‘order’

Alter Table ‘payment’

Alter Table ‘product’

Alter Table ‘product_review’

Alter Table ‘shipping’

Alter Table ‘user’

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
Inserting values.

Insert values into Table ‘user’

Table ‘user’ after insert query.

Insert values into Table ‘agent’

Table ‘agent’ after insert query.

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
Insert values into Table ‘category’

Table ‘agent’ after insert query.

Insert values into Table ‘cart’

Table ‘cart’ after insert query.

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
Insert values into Table ‘product’

Table ‘product’ after insert query.

Insert values into Table ‘product_review’

Table ‘product_review’ after insert query.

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
Insert values into Table ‘order’

Table ‘order’ after insert query.

Insert values into Table ‘payment’

Table ‘payment’ after insert query.

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
Insert values into Table ‘shipping’

Table ‘shipping’ after insert query.

SQL file has the Schema Implementation and Query Implementation.

Explain where and how referential integrity constraints have been incorporated

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
● Referential integrity constraints are incorporated as “ON DELETE CASCADE ON
UPDATE CASCADE” between two tables. This will create the mapping between
tables. This will ensure no orphan records. The records will have Foreign Key (FK).
FK ensures that reference from a row in one table to another must be valid.

Query implementations

● 2 different update queries

o Updating the address of user who is user_id is 3.

▪ UPDATE user
SET address = ‘2985 Blue Ridge’
WHERE user_id = 3;

Before update

After update

o Updating the category_name where the category_id is 4.

Before update

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
After update

● 2 different delete queries

o Delete the review of a product which is given by user_id 4.

▪ DELETE FROM product_review WHERE user_id = 4;

Before delete

After delete

o Delete the order_id 1 from the orders.

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
▪ DELETE FROM `order` WHERE order_id = 1;

Before delete

After delete

● 2 simple select queries related to your tables

o Retrieve all columns from cart where the number of products is more
than 3.

▪ SELECT * FROM cart WHERE num_of_products > 3;

o Retrieve the user id, shipping address and status of orders which still in
'In progress'.

▪ SELECT user_id, shipping_address, status FROM `order`


WHERE status = 'In progress';

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
● 2 nested queries related to your tables

o Retrieve the users who are customers only.

▪ SELECT first_name, last_name, address, email FROM user


WHERE user_id IN (SELECT userid FROM user WHERE
admin = 0 AND vendor = 0);

o Retrieve the products and feedbacks where the rating is less than 3

▪ SELECT product_id, comment FROM product_review


WHERE user_id IN (SELECT userid FROM product_review
WHERE rating <3);

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
● 2 simple join queries related to your tables

o Retrieve the agent name, shipping address and shipping status of


incomplete shippings.

▪ SELECT agent.agent_name, shipping.shipping_address,


shipping.status
FROM agent
INNER JOIN shipping ON
agent.agent_id = shipping.agent_id AND NOT shipping.status
= 'Completed';

o Retrieve the product reviews including customer's firstname, lastname,


comment, and rating

▪ SELECT U.first_name, U.last_name, P.product_name,


PR.comment, PR.rating
FROM product_review PR
INNER JOIN user U ON U.user_id = PR.user_id
INNER JOIN product P ON PR.product_id = P.product_id;

● 2 simple retrieval queries using group by, having clause, and aggregation
functions related to your tables

o Retrieve number of users having more than 1 order.


▪ SELECT U.first_name, U.last_name, COUNT(O.order_id) AS
'Number Of Orders'
FROM (user U

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
INNER JOIN `order` O ON U.user_id = O.user_id)
GROUP BY U.last_name
HAVING COUNT(O.order_id) > 1;

o Retrieve number of Orders with the average grand total more than 300.
▪ SELECT COUNT(order_id) AS 'Number Of Orders',
created_date AS 'Date'
FROM `order`
GROUP BY created_date
HAVING AVG(grand_total) > 300;

● 2 different views, give SQL translations of them, and indicate their


implementation and solutions

o View to display the product name, price and quantity which are above
price 200.

▪ CREATE VIEW Products_Above_Price_200 AS


SELECT product_name, price, qty
FROM product
WHERE price > 200;

SELECT * FROM Products_Above_Price_200;

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*
o View all order details in current day.

▪ CREATE VIEW The_available_orders_for_today AS


SELECT *
FROM `order`
WHERE created_date = CURDATE();

SELECT * FROM The_available_orders_for_today;

Imam University | CCIS | Vice Deanery of Development and Quality Page


PAGE \*
Arabic \*

You might also like