DBS Project
DBS Project
By
DBMS PROJECT
SEMESTER II 2022-23
ER DIAGRAM
EXPLANATION:
● The above given ER diagram has 7 entities denoted by rectangles and all entities have
corresponding attributes drawn in ellipses. The primary key of each entity has been
underlined.
● There are 7 relations represented by diamonds having their cardinality ratios mentioned
over the connecting line segments.
● Total and partial participation can be distinguished based on double and single lines
between relationship set and entity set respectively.
● Dashed Ellipses depict derived attributes.
● Double ovals are used to represent multivalued attributes (note - they were resolved
later in 1NF normalization)
● Double rectangles represent weak entities that don’t have unique identification i.e. don’t
have a primary key and depend upon other entities.
CONVERSION OF ER TO RELATIONAL MODEL
STEP1
We converted all entities and relations as tables and then looked for redundancies
1. CUSTOMER
2. PRODUCTS
3. ORDERS
4. SHIPPING
5. REVIEWS
6. PAYMENT
Code Discount
8. CART
9. PLACES
Cust_id Order_id
10. HAS
Prod_id Order_id
11. SHIPMENT
Tracking_No Order_id
12. GETS
13. TAKES
Payment_id Order_id
14. APPLIES
Code Order_id
STEP 2
We checked for redundancies and thus removed the unnecessary tables. For example, the table
for relation ‘takes’ was removed and instead order_id was added as a Foreign Key into the
Payment table. We have underlined the Primary Keys and have mentioned Foreign Keys using
(F.K.)
1. CUSTOMER
2. PRODUCTS
3. ORDERS
4. SHIPPING
5. REVIEWS
6. PAYMENT
7. COUPON
Code Discount
8. CART
9. HAS
1NF
First normal form prohibits the use of multivalued and/or composite attributes we check each
table for the same
1. CUSTOMER
It has Shipping address as a multivalued as well as a composite attribute. To
tackle this we first divided the column shipping address into S.no, House, City,
State, and Pincode
But these columns were still multivalued and to sort this issue we decided to add
new tuple for every value and so our new primary key became cust_id,add_s.no
Cust_id Name Emaill Phone No. Add_S.no Add_House Add_City Add_State Add_pincode
2. PRODUCTS
They have no multi-valued and/or composite attributes thereby satisfying the
condition for 1NF.
3. ORDERS
They have no multi-valued and/or composite attributes thereby satisfying the
condition for 1NF.
4. SHIPPING
This also had the column Address though this was not multivalued it was
composite and so we broke it down just like in customers.
5. REVIEWS
They have no multi-valued and/or composite attributes thereby satisfying the
condition for 1NF.
6. PAYMENT
They have no multi-valued and/or composite attributes thereby satisfying the
condition for 1NF.
7. COUPON
They have no multi-valued and/or composite attributes thereby satisfying the
condition for 1NF.
8. CART
They have no multi-valued and/or composite attributes thereby satisfying the
condition for 1NF.
9. HAS
They have no multi-valued and/or composite attributes thereby satisfying the
condition for 1NF.
2NF
Relation must follow the condition for 1NF and all Non-Prime attributes should be fully functional
dependent on the Primary Key and not part of the key
1. CUSTOMER
Cust_id Name Emaill Phone No. Add_S.no Add_House Add_City Add_State Add_pincode
In this the candidate key is composed of two attributes Cust_id and Add_S.No and
so we need to check if it violates 2NF.
Cust_id, Add_S.No -> Name, Email, Phone No., Add_House, Add_City, Add_state,
Add_pincode
Now, we can see that the Cust_id can singularly determine Name, Email and Phone No.,
independent of Add_Sno which is also a part of the candidate key and therefore, the
relation must be decomposed.
A. Customer
Cust_ID Name Number Email
B. Customer_Locations
Cust_ID Add.Sno Add_House Add_State Add_City Add_pincode
2. PRODUCTS
Effective_price Price Prod_id Name Description Order_units Stock_units Discount Category
3. ORDERS
Order_id Date Price Status Shipping_ Cust_id (F.K.) Code (F.K)
Ad
4. SHIPPING
Expected Del_Ph_No Zipcode Status Tracking_ Order_id Ship_State Ship_City Ship_House
Date No (F.K,)
6. PAYMENT
Payment_id Amount Type Date Order_id (F.K.)
7. COUPON
Code Discount
8. CART
Cust_id (F.K.) Quantity Prod_id (F.K.)
11. HAS
Prod_id (F.K) Order_id (F.K.)
1. CUSTOMER
Upon applying 2NF normalization, the above relation was decomposed into the following
2 relations :
C. Customer
Cust_ID Name Number Email
D. Customer_Locations
Cust_ID Add.Sno Add_House Add_State Add_City Add_pincode
E. Customer_Location
Cust_id Add_Sno Add_House Add_pincode
F. Customer_city
Add_pincode Add_city
G. Customer_state
Add_city Add_state
2. PRODUCTS
Effective_price Price Prod_id Name Description Order_units Stock_units Discount Category
3. ORDERS
Order_id Date Price Status Shipping_ Cust_id (F.K.) Code (F.K)
Ad
4. SHIPPING
Expected Del_Ph_No Zipcode Status Tracking_ Order_id Ship_State Ship_City Ship_House
Date No (F.K,)
Just as observed in Customer relation, Non-prime attribute Zipcode can determine other
non-prime attributes like Ship_State and Ship_city. Also, we can obtain Ship_state from
Ship_City, both being non-prime attributes. This violates the conditions for 3NF and the
relation Shippping must be decomposed in similar manner:
H. Ship_city
Zipcode Ship_city
I. Ship_state
Ship_city Ship_state
J. Ship_Location
Expected_ Del_Ph_No Zipcode Status Tracking_ Ship_House Order_
Date No id
5. REVIEWS
Rating Feedback Date Title Prod_id (F.K.)
6. PAYMENT
Payment_id Amount Type Date Order_id (F.K.)
7. COUPON
Code Discount
8. CART
Cust_id (F.K.) Quantity Prod_id (F.K.)
Customers
c_id :Stores the customer id, can't be null and is the primary key
C_name: Stores the Customer's name, can't be null
c_email : Stores the Email of the customer, can’t be null
c_phoneno : Stores the Phone Number of the customer, Can't be null
Constraints are applied so that valid emails i.e one having @ and a domain name are
allowed, only 10 digit phone numbers can be stored
Customer_Location
C_id: Stores the customer id, can't be null also acts as foreign key to table customer
C_address_sno: Stores the S.No. of the address of that user default value is set as 1
C_address_house: Stores the line 1 of address eg C390, SFS Flats
C_address_pincode: Stores the pincode of the address
Constraints are added to ensure that only valid 6 digit pin codes are entered
Customer_city
C_city: Stores the name of the city
C_pincode: Stores the pincode of the city, acts as the primary key also refers to the table
Customer_location
No null values are allowed to be stored, also while inserting we have tried to use
INSERT IGNORE INTO to prevent redundant entries
Products
P_id Stores the id of the product, acts as the primary key
p_description : Stores the description of the product
P_category: Stores the category of the product
P_price: Stores the price of the product
p_effective_price : Is a derived attribute and stores the effective price i.e. price after
discount
P_discount: Store the percentage discount on the product
P_units_on_order: Stores the amount of products on order
P_units_in_stock: Stores the number of products in stockI)
Constraints are added to ensure that the units on stock and units on order never go into
negative also discount is only allowed to store values between 0 to 100
Coupons
c_coupon_code Stores the coupon code also acts as the primary key
c_discount Stores the discount percentages
Constraints are added to ensure that the discount is always between 0 to 100 percent
Orders
O_id Stores the order id and acts as the primary key
O_date Stores the date of placing the order
O_status Stores the status of the order
o_coupon_code Stores the applied coupon code, its default value is set to ‘ZERO’ which
points to 0% discount, references to table Coupons
o_house Stores the shipping address line 1
o_pincode Stores the pincode and refers to the table customer_city
Payment
p_id Stores a unique payment id and acts as primary key o_id VARCHAR(5) NOT NULL,
p_amount Stores the amount transferred/received
p_type To store the mode of payment
P_date To store the date of payment
O_id acts as a foreign key to refer to the table orders
Constraints like cascade delete is added so that if the order is deleted its payment is also
deleted
Note: for cancellation a negative payment is generated and the status is set to canceled
Shipping
s_tracking_id Stores the tracking id and allows user to track package, acts as primary
key s_date Stores expected date of shipping
s_phoneno Stores the phone number of the delivery executive
s_status Tells the status of the delivery
o_id Refers to the order it is delivering
Constraints like checking phone number and cascade delete are added ere
Has
p_id Stores the product id in the order, refers to table product
o_id stores the order id, refers to table orders
p_qty stores the quantity of product in the order
Cart
c_id gives the id of the user of the cart, refers to the table customers
p_id Stores the id of the product added into the cart, refers to the table products
p_qty Stores quantity of the product added into the cart
Constraints like cascade delete is added to ensure that the entries from cart is removed
if a user is deleted
SQL QUERIES AND THEIR OUTPUTS
OUTPUT:
OUTPUT:
#QUERY 3 RECOMMENDING SIMILAR PRODUCTS
OUTPUT:
OUTPUT:
OUTPUT:
#QUERY 6 PRODUCT INFORMATION
OUTPUT:
OUTPUT:
#QUERY 8 ADD PRODUCT TO CART
OUTPUT:
OUTPUT:
OUTPUT:
#QUERY XX - VIEWING A REVIEW
OUTPUT:
OUTPUT:
OUTPUT:
#QUERY 14 PROCESSING A REFUND
OUTPUT:
OUTPUT:
OUTPUT: