You are on page 1of 33

Data Management and

Relational Modelling

1
Course: Data Engineering - I
Edit Master
Lecture textManagement
On: Data styles and
Relational Modelling
Instructor: Vishwa Mohan

2
Session 5 | Use Case Example
Session Overview
Identifying any partial
functional dependency and
Understanding the attributes of a use
transitive dependencies.
case example

Identifying the main entities


When is Data Normalization required?
Consider an Example
A food delivery company has It has defined various attributes that
provided the restaurant menu on its are used by the company to store
app and offers delivery services to information.
its customers.
We are given the attributes, and we
Once an order is received by the have to design the logical layer of
restaurant, a delivery employee is our database.
selected to deliver the order.
Consider All These Attributes

Attributes Attributes

Order ID Restaurant Category

Order Date Restaurant Membership

Restaurant Name Customer Name

Restaurant Address Customer Phone Number

Restaurant Phone Customer Address


Number
Cont’d...
Restaurant Type Item Purchased
Consider All These Attributes

Attributes Attributes

Item Quantity Payment Mode

Item Type Delivery Employee Name

Item Category Vehicle Number

Customer Membership Pickup Time

Coupon Applied Delivered Time

Price Paid Total Delivery Time


Why Does This Data Need to Be Modelled?
Order Order Date Restaurant Restaurant Restaurant Restaurant Restaurant Restaurant
ID Name Address Phone Number Type Category Membership

10 20Jan2020 South indian plot 5, 9768546320 South Indian Veg Plan Premium
Food mumbai

Customer Customer Customer Customer Item Item Item Type Item


Name Phone Address Membership Purchased Quantity Category
Number

Virat 9765438210 plot 10, Plan premium idli, dosa 5, 2 South Indian, Veg, Veg
mumbai South Indian

Coupon Price Payment Delivery Employee Vehicle Pickup Time Delivered Total Delivery
Applied Paid Mode Name Number Time Time

COUPON12 200 Cash Rohit VEH1234 5:30 pm 6:00 pm 30 mins


The Main Entities

Customer Restaurant Delivery Employee

Customer ID Restaurant ID Delivery Employee ID


Name
Name
Name
Phone Number
Type
Customer Address Vehicle Number
Category
City Date of joining
Address
State
Membership Plan
City
Customer Membership

State Membership Plan Details


Customer Membership Price
The Item Entity
Strong Entity
Weak Entity

Restaurant
Item
Restaurant ID
Item ID
Name
Restaurant ID

Item Name Type

Item Price Category

Item Description Address

Item Type
City
Item Category
State
Customer and Item Entities
The relation between the customer and item tables is many-to-many.
To implement a many-to-many relation, there will be one more entity ‘order’ that has a
many-to-one relation with customer table as well as order table.

Customer Item
Customer ID
Item ID
Name
Restaurant ID
Phone Number
Item Name
Customer Address
Item Price
City
Item Description
State Item Type
Customer Membership
Item Category
Customer Membership Price
The Order Entity

Customer

Customer Id Order
Name Customer ID
Phone Number Coupon Applied
Customer Address Price Paid
City Total Delivery Time
State

Customer Membership

Customer Membership Price


The Order Entity

Order
Item
Customer ID
Item ID
Restaurant ID
Restaurant ID
Item ID
Item Name
Coupon Applied
Item Price
Price Paid
Item Description
Total Delivery Time
Item Type

Item Category
The Order Entity
Customer Item
Order
Customer ID
Item ID
Customer ID
Name
Restaurant ID
Restaurant ID
Phone Number
Item Name
Item ID
Customer Address
Item Price
Coupon Applied
City
Item Description
Price Paid
State
Item Type
Total Delivery Time
Customer
Membership Item Category

Customer
Membership Price
The Order Entity

Delivery Employee
Order

Customer ID Delivery Employee ID

Restaurant ID
Name
Item ID
Vehicle Number
Delivery Employee ID

Coupon Applied Date of Joining

Price Paid
Membership Plan
Total Delivery Time
Membership Plan Details
Order
All Entities Item
Customer ID Item ID
Customer
Restaurant ID
Restaurant ID
Customer ID
Item ID Item Name
Name
Delivery Employee ID ...
Phone Number
Coupon Applied
Customer Address
Price Paid
...
Total Delivery Time

Delivery Employee Restaurant

Delivery Employee ID Restaurant ID

Name Name

Vehicle Number Type

... ...
Functional Dependencies

Order Order
There is no composite key in
Customer ID this table to uniquely identify Order ID
every record.
Restaurant ID Customer ID

Item ID If there is an attribute order Restaurant ID


ID for each order, there can
Delivery Employee ID be a composite key. Item ID

Coupon Applied Delivery Employee ID


One order can have two
Price Paid items. This will cause the Coupon Applied
order ID to be the same for
Total Delivery Time two rows. Thus, it cannot act Price Paid
as a primary key.
Total Delivery Time
Functional Dependencies
Order ID Customer ID Restaurant ID Item Delivery Coupon Price Total
ID Employee ID Applied Paid Delivery
Time

50 C101 R112 2, 3 D12 C100, C200 120, 130 50 mins

Order ID Customer ID Restaurant ID Item Delivery Coupon Price Total


ID Employee ID Applied Paid Delivery
Time

50 C101 R112 2 D12 C100 120 50 mins

50 C101 R112 3 D12 C200 130 50 mins


Functional Dependencies Customer ID

Restaurant ID

Delivery Employee
ID
Order ID

Total Delivery Time

Item ID

Coupon Applied

Price Paid
Functional Dependencies
Order

Order ID Order
Order Item
Customer ID Order ID
Order ID
Restaurant ID Customer ID
Item ID
Item ID Restaurant ID
Coupon Applied
Delivery Employee ID Delivery Employee ID
Price Paid
Coupon Applied Total Delivery Time

Price Paid

Total Delivery Time The order table is separated


into two different tables to
remove any partial
dependency.
If there is a composite key in the
Functional Dependencies table, partial dependencies may
exist. If there is only one primary
key, there cannot be any partial
dependencies.
Customer
Restaurant
Customer ID Delivery Employee
Restaurant ID
Name Delivery Employee ID

Phone Number Name


Name
Customer Address Type
Vehicle Number
City Category
Date of Joining
State
Address
Membership Plan
Customer Membership
City
Customer Membership Membership Plan Details
Price State
Functional Dependencies

Item Item entity is a weak entity. It


depends on the primary key of
Item ID restaurant entity to uniquely
Restaurant ID
identify each record in the item
table.
Item Name

Item Price
Restaurant ID is the foreign key to
Item Description the restaurant table. Item Id and
Item Type
restaurant ID form the composite
key for the table. All the non-prime
Item Category attributes fully functionally
dependent on prime attributes.
Transitive Dependencies in Customer Entity

Customer

Customer ID Customer ID -> Customer


Membership -> Customer
Name Membership Price

Phone Number

Customer Address
Customer ID -> City -> State
City

State

Customer Membership

Customer Membership Price


Transitive Dependencies in Customer Entity
Customer Membership

Customer Membership ID
Customer
Customer Membership Price
Customer ID
City
Name
Zip Code
Phone Number
City Name
Customer Address
State ID
Zip Code

Customer Membership ID State

State ID

State Name
Transitive Dependencies in Restaurant Entity
Restaurant

Restaurant ID
Restaurant ID -> City -> State
Name

Type
Restaurant ID -> Type -> Type
Category Details
Restaurant ID -> Category ->
Address
Category Details
City

State
Transitive Dependencies in Restaurant Entity
Restaurant Restaurant Category

Restaurant ID Category ID

Category Name
Name
Category Description
Type ID

Category ID City

Zip Code
Address
City Name
Zip Code
State ID
Restaurant Type
State
Type ID
State ID
Type Name
State Name
Type Description
Transitive Dependencies in Delivery Employee Entity
Delivery Employee

Delivery Employee ID
Delivery Employee ID -> Membership Plan
-> Membership Details
Name

Vehicle Number

Date of Joining

Membership Plan

Membership Plan Details


Transitive Dependencies in Delivery Employee Entity

Delivery Employee

Delivery Employee ID Employee Membership

Name Membership Plan ID

Customer Membership Detail


Vehicle Number

Date of Joining

Membership Plan ID
Transitive Dependencies in Item Entity
Item

Item ID

Restaurant ID

Item Name

Item Price Item ID -> Type -> Type Details


Item Description
Item ID -> Category -> Category
Details
Item Type

Item Category
Transitive Dependencies in Item Entity
Item Category

Item Category ID
Item ID Category Name
Restaurant ID Category Description

Item Name
Item Type
Item Price
Type ID
Item Description
Type Name
Type ID
Type Description
Category ID
Transitive Dependencies in Order Entity

Order

Order ID Order Item

Customer ID Order ID

Restaurant ID Item ID

Delivery Employee ID Coupon Applied

Total Delivery Time Price Paid


All Entities
City State
Restaurant
Type
Customer
Customer Restaurant
Membership
Order Restaurant
Category

Order Item
Delivery Item
Employee Item
Category

Employee Item Type


Membership
Thank you

You might also like