🔗 Data Modeling & Relationships
Shows unique values with count
Returns all different values in a column, including those that appear multiple times. Only shows the number of distinct values, not how many times each appears.
(Only counts unique types)
Example: [1, 2, 2, 3] → DISTINCT gives 3 values
Only values that appear once
Returns only those values that appear exactly one time in the dataset. Excludes any value that is repeated.
(No duplicates allowed)
Example: [1, 2, 2, 3] → UNIQUE gives [1, 3]
When Distinct = Unique
A column becomes a primary key when every value in it is both distinct AND unique - meaning each value appears exactly once with no duplicates.
(Each value appears only once)
Example: Employee_ID, Student_ID, Order_ID
Runs when IF condition fails
ELSE IF is executed only when the initial IF condition evaluates to FALSE. It provides an alternative condition to check.
ELSE IF (condition2) → Execute
ELSE → Default
Time between order and delivery
Shipment duration is calculated by subtracting the order date from the ship date to determine processing time.
Example: Ship: Jan 10, Order: Jan 5 → 5 days
Creates relationships between tables
Data modeling establishes connections and relationships between multiple tables in a database, enabling complex queries and analysis across related data.
Organize data efficiently, reduce redundancy, maintain data integrity, and enable powerful analytics through table relationships.
⭐ Star Schema
Central Fact Table Structure
(Sales)
• One central fact table
• Multiple dimension tables
• Direct connections to fact table
• Denormalized structure
• Faster query performance
❄️ Snowflake Schema
Normalized Dimension Structure
(Sales)
• Dimension tables have sub-dimensions
• Normalized structure
• Indirect connections via dimensions
• Saves storage space
• More complex queries
The fact table does NOT directly connect to sub-dimension tables. In a snowflake schema, the fact table connects only to dimension tables, and dimension tables connect to their sub-dimension tables.
| Aspect | ⭐ Star Schema | ❄️ Snowflake Schema |
|---|---|---|
| Structure | Simple, denormalized | Complex, normalized |
| Dimension Tables | Connect directly to fact table | Connect to sub-dimensions |
| Query Performance | Faster (fewer joins) | Slower (more joins) |
| Storage Space | More space (redundancy) | Less space (normalized) |
| Complexity | Easy to understand | More complex |
| Maintenance | Easier to maintain | More difficult |
| Best For | Quick queries, reporting | Large datasets, storage efficiency |
Comments
Post a Comment