Data Modeling-The Foundation of Data
Data Modeling-The Foundation of Data
Modeling
The Foundation of Data
02 codebasics.io
Data
Data Modeling
Analysis
*Me
Looking at the meme above, you might understand the importance of data modeling.
DATA MODELING:
Data
Sales Product
Customer
Just like a blueprint visualizes the plan and details for a house, data modeling creates
a visual representation of data entities and the relationships between data elements.
04 codebasics.io
Name
1
Address
Phone Number
Entities:
These are the main things we want to store information about. For instance, in a
business, an entity could be "Customer" or "Product."
Attributes:
These are the specific pieces of information about an entity. For a "Customer,"
attributes could include name, address, and phone number.
Relationships:
These define how entities are connected or related to each other. For example, a
"Customer" can have a relationship with an "Order."
05 codebasics.io
1 2 3
Product
Sales Date
Customer
06 codebasics.io
Product
Product_id
Name
Category
Unit Price
Color
Rating Sales Date
Description
Customer_id (FK) Date
Date (FK) Year
Product_id (FK)
Customer
Fiscal_Year
Sold_QTY Month
Customer_id Sales_Amount Quarter
Name
Region
Address
Phone_NO
Email_id
Product
Product_id Integer
Name Varchar(30)
Category Varchar(30)
Unit Price Integer
Color Varchar(30)
Rating Integer Sales Date
Description Varchar(30)
Customer_id (FK) Integer Date Date
Date (FK) Date Year Integer
Product_id (FK) Integer Integer
Customer
Fiscal_Year
Sold_QTY Integer Month Varchar(30)
Customer_id Integer Sales_Amount Float Quarter Integer
Name Varchar(30)
Region Varchar(30)
Address Varchar(30)
Phone_NO Varchar(10)
Email_id Varchar(30)
07 codebasics.io
TYPES OF TABLES:
Data modeling establishes a connection and flow of data between tables, typically
consisting of fact tables surrounded by dimension tables, along with the relationships
between these tables.
1 FACT TABLE:
A fact table contains measurements, metrics, or facts about a business process.
It generally compresses transactional data.
It has two types of columns: one representing facts of the business and another
containing foreign keys to dimension tables.
Example: A Sales fact table contains data on store sales, detailing the quantity
of each product sold and the revenue generated from each sale.
Foreign
Facts Key
Fact Table
Facts: amount, date, quantity. These columns represent the business facts.
Foreign keys: customer_id, product_id. These columns contain foreign keys
that link to dimension tables.
08 codebasics.io
2 DIMENSION TABLE:
Fact tables are connected to dimension tables using foreign keys.
Dimension tables consist of attributes that describe the objects of a fact table.
Each dimension table includes a primary key that uniquely identifies each record
and using this key dimension table associates with fact tables.
Primary Key
Dimension Table
TYPES OF RELATIONSHIPS:
1 *
1 One-to-One Relationship:
Telangana
Hyderabad
Each row in the first table is mapped to only one row in the second table.
For example, each state has only one capital.
2 One-to-Many Relationship:
In a one-to-many relationship, each row in the first table can be associated with
multiple rows in the second table.
For example, a customer can place several orders over time, but each order is tied
to a specific customer.
11 codebasics.io
3 Many-to-One Relationship:
Multiple rows in the first table are mapped to a single related row in the second
table.
4 Many-to-Many Relationship:
Multiple records from one table relate to multiple records from another table.
12 codebasics.io
Many-to-Many Relationship:
For example, more than one teacher can teach multiple courses. Dhaval teaches
ML and Power BI; Power BI is taught by both Dhaval and Hem.
E n a b l i n g C a r e e r s
SCAN TO JOIN
codebasics.io