0% found this document useful (0 votes)
8 views24 pages

Data Modelling

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views24 pages

Data Modelling

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Data Modelling

Session 1: Database Design Re-cap


Data Warehouse

Data warehouse is
• Subject-oriented
• Integrated
• Non-volatile
• Time-variant
collection of data points
Journey of Data in an Organization
ER Diagram
Star Schema Dimension
Table

Dimension Dimension
Table Table

Fact
Table

Dimension Dimension
Table Table
Snowflake Schema Dim Dim
Table L2 Table L2

Dim
Dim Table L1 Dim
Table L2 Table L2

Dim Dim
Dim
Table L1 Table L1 Dim
Table L2
Fact Table L2

Dim
Table L2
Table Dim
Table L2
Dim Dim
Table L1 Table L1

Dim Dim
Table L2 Dim Table L2
Table L1

Dim Dim
Table L2 Table L2
DDL and DML
Data Definition Language Data Manipulation Language
• CREATE • INSERT
• Schema • UPDATE
• Tables
• DELETE
• Views
• Constraints
• ALTER
• DROP
• Operates on the structure of the • Operates on the contents of the
Entity Entity
Data Modelling
Session 2: Building blocks of data modelling
Introduction to Data Modelling
Database Design
Design

Development/Implementation

Manipulation

Revision

Production

Maintenance
Relational Schemas
Advantages Disadvantages

• Data structuring is easy • It’s very rigid, restricts flexibility


• Efficient querying as • Relational Databases do not
optimizations like indexing is scale out horizontally very well,
possible can’t keep adding more and
• Easy to navigate and explore the more tables/columns
data • Very minimal/no support on
• Relationships can be easily semi-structured data
defined between data points
Relational vs Non-Relational
Schemas
ACID BASE

Atomic: Everything in a transaction


Basic Availability: Supports basic needs for
succeeds or the entire transaction is
data capture
reverted
Consistent: A transaction is consistent Soft state: The state of the system could
across the database change over time

Isolated: Transactions are independent of Eventual consistency: Rather than being


each other consistent after each transaction, it attains
that state of consistency eventually
Durable: Completed transactions are
retained, even when the server restarts
Data Modelling
Session 3: Problem-solving using Data Modelling
Problem Statement: Create a data model for
retail chain to understand its consumer behavior
• Sales Transactions
• Product Details
• Customer Information
• Employee Information
• Product Inventory Inflow
• Branches details
• Campaigns/Discounting Information
• Details of Customer Complaints
Database Design
customer_info order_product_mapping
* customer_id * order_id
first_name * product_id
last_name quantity_ordered
gender
email
sales_fact
* order_id
customer_id
order_date
store_id

branch_details product_info
* store_id * product_id
store_name product_name
area product_category
city list_price
state sale_price
Database Creation
• CREATE DATABASE databasename;
• CREATE SCHEMA schemaname;

• USE databasename

• DROP DATABASE databasename;


• DROP SCHEMA schemaname;
Table Creation
CREATE TABLE table_name DROP TABLE table_name;
(
column1 column_definition,
column2 column_definition,
...
CONSTRAINT [constraint_name]
PRIMARY KEY (column1, column2, ... column_n)
ALTER TABLE table_name
);
ADD CONSTRAINT [ constraint_name ]

ALTER TABLE table_name


FOREIGN KEY (column1) REFERENCES
table2_name(reference_column);
ADD CONSTRAINT [ constraint_name ]
PRIMARY KEY (column1, column2, ... column_n);
Database/Table Manipulation
INSERT INTO table_name
VALUES (value1, value2, value3, ...);

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

DELETE FROM table_name WHERE condition;

DELETE table_name;
Understanding Customer Behaviour
• Number of Transactions by Gender
• Transactions by Men
• Transactions by Women
• Number of customers who have placed an order from more than 1
store
• City with highest number of orders
• Area with highest sales (Sum of all sales prices)
• State with highest customers

You might also like