Data Modeling Advanced Concepts & Database Tables and Normalization
Data Modeling Advanced Concepts & Database Tables and Normalization
For example:
Normalized Schema: In a normalized schema, the customer table would store customer details, and the
order table would store orders. A Customer_ID would serve as the foreign key in the order table.
De-normalized Schema: In a denormalized schema, customer details might be repeated in each order
record to speed up query performance (at the cost of potential data anomalies).
7. Denormalization
Denormalization is the process of deliberately introducing redundancy into a database schema by merging
tables or storing redundant data to improve query performance.
Why Denormalize?
Performance Improvement: Sometimes, normalized databases require complex joins, which can slow
down query performance.
Faster Data Retrieval: By denormalizing, queries can be optimized to reduce the number of joins
required, leading to faster data retrieval.
Example: In an order database:
Normalized: The customer table stores customer info, and the orders table stores order info with a
Customer_ID as a foreign key.
Denormalized: Customer information is duplicated in the order table, so each order record includes
customer details.
Real-World Example:
Consider an e-commerce system with three entities: Customers, Orders, and Products.
1. Non-Normalized Design:
Order_ID Customer_Name Customer_Address Product_Name Product_Price Quantity
1 John Doe 123 Elm St Laptop 1200 2
2 Jane Smith 456 Oak St Phone 800 1
2. First Normal Form (1NF):
In 1NF, we ensure atomicity. If we were storing multiple products per order, we would split them:
Order_ID Customer_Name Customer_Address Product_Name Product_Price Quantity
1 John Doe 123 Elm St Laptop 1200 2
1 John Doe 123 Elm St Phone 800 1
2 Jane Smith 456 Oak St Laptop 1200 1
3. Second Normal Form (2NF):
We split the customer information into a separate table to remove partial dependencies:
Customers Table:
Customer_ID Customer_Name Customer_Address
1 John Doe 123 Elm St
2 Jane Smith 456 Oak St
Orders Table:
Order_ID Customer_ID Product_Name Product_Price Quantity
1 1 Laptop 1200 2
1 1 Phone 800 1
2 2 Laptop 1200 1
4. Third Normal Form (3NF):
To further normalize, ensure that no transitive dependencies exist (e.g., customer address should not depend on
customer name):
Customers Table:
Customer_ID Customer_Name Customer_Address
1 John Doe 123 Elm St
2 Jane Smith 456 Oak St
Orders Table:
Order_ID Customer_ID Product_Name Product_Price Quantity
1 1 Laptop 1200 2
1 1 Phone 800 1
2 2 Laptop 1200 1