Chapter 1
Data Concepts and Environments
Course: Comptia Data Da0 001
Subject: Subjet Comptia Data Da0 001
Chapter: Data Concepts And Environments
1. Introduction to Data Schemas and Dimensions
In the realm of databases and data analysis, understanding data schemas and dimensions is fundamental to structuring, querying, and analyzing data effectively. These concepts determine how data is stored and accessed, particularly in large-scale applications such as business intelligence, data warehousing, and big data analytics.
Data Schema
A data schema refers to the logical structure of a database, defining how data is stored, organized, and related. It consists of tables, views, constraints, relationships, indexes, and keys that dictate how data interacts within a database. A well-designed schema ensures efficient data retrieval, storage, and maintenance.
Types of Data Schemas
- Physical schema – Defines how data is physically stored in the system, including disk partitions, indexing, and storage formats.
- Logical schema – Represents the overall structure of the database in terms of tables, columns, keys, and relationships.
- Conceptual schema – Provides an abstract representation of data and its relationships without considering the specific database system.
Dimensions in Data Warehousing
A dimension is an attribute or a perspective by which data is categorized and analyzed in a data warehouse. Dimensions provide context to numerical facts and measures, making them critical in online analytical processing (OLAP) and business intelligence applications.
Examples of Dimensions in Data Warehousing
- Time dimension (year, month, day, quarter)
- Geographic dimension (country, city, region)
- Product dimension (category, brand, model)
- Customer dimension (customer ID, name, segment)
A well-defined star schema or snowflake schema is used in data warehouses to organize facts (measurable numerical values) and dimensions efficiently.
2. Types of Databases
A database is a structured collection of data that allows efficient storage, retrieval, and manipulation. The two primary types of databases are relational databases (RDBMS) and non-relational databases (NoSQL).
a. Relational Databases (RDBMS)
A relational database organizes data in a structured manner using tables (relations) that are connected via keys. The schema enforces strict rules, ensuring that all data follows a predefined format. These databases use SQL (Structured Query Language) for querying and managing data.
Key Features of RDBMS
- Tables and relationships – Data is stored in tables with predefined columns and relationships enforced using primary and foreign keys.
- Normalization – Reduces data redundancy by splitting data into related tables.
- ACID compliance – Ensures reliable transactions through:
Atomicity (transactions are all-or-nothing) Consistency (data remains in a valid state) Isolation (transactions do not interfere with each other) Durability (data is permanently stored)
- Atomicity (transactions are all-or-nothing)
- Consistency (data remains in a valid state)
- Isolation (transactions do not interfere with each other)
- Durability (data is permanently stored)
Examples of Relational Databases
| Database | Key Features | Use Cases | | MySQL | Open-source, fast, supports ACID transactions | Web applications, CMS (WordPress, Joomla) | | PostgreSQL | Advanced SQL compliance, supports complex queries | Data science, analytics, geospatial databases | | Oracle Database | Enterprise-grade, highly scalable | Large enterprises, financial services | | Microsoft SQL Server | Integration with Windows ecosystem, high security | Enterprise applications, corporate databases |
Real-Life Example
A retail company that tracks sales uses an RDBMS such as MySQL. The database contains multiple tables:
- Customers (customer_id, name, email, phone)
- Products (product_id, name, category, price)
- Sales (sale_id, customer_id, product_id, date, amount)
A foreign key relationship links customer_id in Sales to Customers, ensuring referential integrity.
b. Non-Relational Databases (NoSQL)
A NoSQL database provides a more flexible data storage model compared to relational databases. It is designed to handle large volumes of unstructured, semi-structured, or distributed data.
Key Features of NoSQL Databases
- Schema-less design – No strict table structures, allowing dynamic and flexible data storage.
- Horizontal scalability – Can distribute data across multiple servers for scalability.
- High performance – Optimized for fast read/write operations, often used in real-time applications.
Types of NoSQL Databases
| Type | Description | Examples | | Document stores | Store data as JSON/BSON documents | MongoDB, CouchDB | | Key-value stores | Store key-value pairs | Redis, DynamoDB | | Column-family stores | Store data in column-based format | Apache Cassandra, HBase | | Graph databases | Represent data as nodes and relationships | Neo4j, ArangoDB |
Examples of NoSQL Databases
- MongoDB – Stores data in JSON-like format; commonly used in e-commerce and content management systems.
- Cassandra – A distributed NoSQL database used by Facebook, Netflix, and Twitter for handling big data workloads.
- Redis – A key-value store used for caching and real-time analytics.
- Neo4j – A graph database used for social networks, fraud detection, and recommendation systems.
Real-Life Example
An e-commerce platform like Amazon might use MongoDB for storing product details, since different products have varying attributes (e.g., clothing may have "size", "color", while electronics may have "brand", "processor"). A relational database would require complex schema changes to accommodate different structures, whereas a document-based NoSQL database allows storing flexible, dynamic product information.
c. Choosing Between RDBMS and NoSQL
When to Use an RDBMS?
- When data consistency is crucial (e.g., banking transactions).
- When relationships between entities are complex (e.g., ERP systems).
- When the database schema is stable and does not frequently change.
When to Use NoSQL?
- When handling large volumes of unstructured data (e.g., social media, IoT data).
- When horizontal scalability is required (e.g., distributed systems, cloud-native applications).
- When dealing with high-speed read/write operations (e.g., real-time analytics, caching).
d. Data Schema in the Context of Data Warehouses
In the context of data warehousing and business intelligence, data schemas are used to define how data is structured to enable efficient querying and reporting. The most common data schema used in data warehouses are star schemas and snowflake schemas.
- Star Schema: In a star schema, a central fact table (containing quantitative data) is connected to several dimension tables (containing descriptive attributes). This schema is simple and easy to understand. Example: In a sales data warehouse, the fact table might store metrics like SalesAmount, QuantitySold, and DiscountApplied, while dimension tables might store details like Product, Time, Store, and Customer.
- Snowflake Schema: This is a more complex variation of the star schema where dimension tables are normalized. This means the dimensions are broken down into additional tables to eliminate redundancy. Example: In a snowflake schema, a Product dimension table might be split into multiple sub-tables like ProductCategory, ProductType, and ProductSupplier.
e. Dimensions in Data Warehousing
In a data warehouse, dimensions are descriptive elements that provide context to the measures (facts) stored in a fact table. For example, in a retail sales data warehouse, the facts might be sales amounts or quantities, and the dimensions might include Time, Store, Product, and Customer.
Common Dimensions Include:
- Time: Represents dates, weeks, months, quarters, or years.
- Geography: Includes regions, countries, cities, etc.
- Product: Describes the products being sold (e.g., product category, brand, size).
- Customer: Information about the customers (e.g., name, address, loyalty status).
Real-life Example: In a business intelligence scenario, a company might use dimensions to analyze sales over time. By filtering the data by Time dimension (e.g., year, quarter, month) and grouping it by the Product dimension, the company can generate insights on which products are performing better in different periods.
3. Introduction to Data Mart, Data Warehousing, and Data Lake
Data management is a crucial component of modern businesses and organizations that rely on data-driven decision-making. As data grows in volume and complexity, various architectures and storage solutions have been developed to handle data efficiently. Among them, data marts, data warehouses, and data lakes are widely used to store, manage, and analyze data, each serving a different purpose.
A data mart is a small, department-focused repository that provides quick access to specific business data. A data warehouse is a large, centralized system designed to store and integrate data from multiple sources for reporting and business intelligence. A data lake, on the other hand, is a highly scalable storage system that holds structured, semi-structured, and unstructured data in its raw form for future processing.
1. Data Mart
A data mart is a subset of a data warehouse that focuses on a particular business unit or department, such as sales, marketing, or finance. It is designed to provide fast and easy access to specific data, making it an efficient solution for departments that require specialized analytics.
Key Characteristics of Data Marts
- Department-Specific Focus – Designed for a particular group, such as HR, sales, or finance.
- Smaller Data Volume – Only contains relevant data for its intended users, reducing storage and processing complexity.
- Faster Query Performance – Optimized for quick data retrieval to support decision-making.
- Easier Maintenance – Requires fewer resources to manage compared to a data warehouse.
Types of Data Marts
- Dependent Data Mart – Extracted from an existing data warehouse.
- Independent Data Mart – Created from operational systems or external sources without using a data warehouse.
- Hybrid Data Mart – Combines data from both a data warehouse and other external systems.
Real-Life Example
A retail company may create a sales data mart that stores only sales-related data from the larger corporate data warehouse. This allows the sales team to quickly analyze trends such as product performance, seasonal fluctuations, and customer purchase behavior without having to sift through unrelated data from HR or logistics.
2. Data Warehousing
A data warehouse is a centralized system designed to store, integrate, and analyze large amounts of historical data from multiple sources. It is structured to support complex queries, reporting, and decision-making.
Key Characteristics of Data Warehouses
- Integration of Multiple Data Sources – Consolidates data from various operational systems, external databases, and third-party sources.
- Subject-Oriented Organization – Data is categorized by business functions such as customers, sales, or inventory.
- Historical Data Storage – Maintains large volumes of past data to facilitate trend analysis and forecasting.
- Optimized for Analytical Queries – Supports business intelligence, reporting, and advanced analytics.
Data Warehouse Architectures
- Star Schema – A simple design where a central fact table is connected to multiple dimension tables.
- Snowflake Schema – A more complex version of the star schema with normalized dimensions.
- Fact Constellation – A more flexible schema with multiple fact tables sharing common dimension tables.
Real-Life Example
A financial services company integrates banking transactions, investment records, and customer interactions into a centralized data warehouse. This enables analysts to examine customer spending habits, detect fraud, and predict market trends.
Challenges of Data Warehousing
- High cost of storage and processing due to structured data organization.
- Long implementation time due to the need for data transformation and integration.
- Inflexibility when handling rapidly changing data formats.
3. Data Lake
A data lake is a storage repository designed to hold vast amounts of raw data in its native format until needed for processing. Unlike data warehouses, which require structured data, data lakes can store structured, semi-structured, and unstructured data, making them highly flexible.
Key Characteristics of Data Lakes
- Storage of Raw Data – Retains all data in its original form without requiring transformation.
- Scalability – Can handle massive volumes of data across distributed cloud storage.
- Supports Various Data Types – Stores structured (databases), semi-structured (JSON, XML), and unstructured (videos, logs, sensor data) data.
- Flexible Processing – Allows the use of tools such as Apache Spark, Hadoop, and machine learning algorithms to extract insights.
Use Cases of Data Lakes
- Big Data Analytics – Processing massive datasets using parallel computing.
- Machine Learning & AI – Training models on diverse datasets, including images and text.
- IoT Data Storage – Collecting and analyzing data from smart devices and sensors.
Real-Life Example
A healthcare organization uses a data lake to store various types of data, including MRI scans, electronic health records (EHR), and patient sensor data from wearable devices. By leveraging machine learning, doctors can detect early signs of diseases and optimize patient treatments.
4. Online Transaction Processing (OLTP)
OLTP refers to systems that manage real-time transactional data. These systems are optimized for handling a large number of short, frequent transactions such as updating, inserting, and deleting records.
Key Characteristics of OLTP Systems
- Real-Time Data Processing – Ensures fast transaction execution with low latency.
- High Transaction Volume – Designed to handle thousands of concurrent operations.
- Normalization – Data is structured to reduce redundancy and maintain consistency.
Examples of OLTP Systems
- Retail POS Systems – Process sales transactions in real time.
- Banking Systems – Handle account balance updates, fund transfers, and withdrawals.
- E-commerce Platforms – Process customer orders, payments, and inventory updates.
Real-Life Example
A customer purchases a product on an e-commerce website. The OLTP system immediately updates the inventory, processes the payment, and records the transaction in the customer's purchase history.
5. Online Analytical Processing (OLAP)
OLAP is designed for analyzing large datasets and performing complex queries to uncover trends and patterns. It is typically used for reporting, business intelligence, and strategic decision-making.
Key Characteristics of OLAP Systems
- Multidimensional Analysis – Enables data analysis across multiple dimensions such as time, geography, and product category.
- Aggregation and Summarization – Supports precomputed metrics like averages, totals, and percentages.
- Pre-aggregated Data Storage – Uses OLAP cubes to optimize query performance.
Types of OLAP
- MOLAP (Multidimensional OLAP) – Stores precomputed data in OLAP cubes for fast querying.
- ROLAP (Relational OLAP) – Uses SQL-based queries to perform on-the-fly aggregations.
- HOLAP (Hybrid OLAP) – Combines MOLAP and ROLAP features for optimized performance.
Examples of OLAP Systems
- Microsoft SQL Server Analysis Services (SSAS) – Used for advanced business intelligence reporting.
- IBM Cognos – Provides dashboards and reports for business analytics.
- Oracle Essbase – Enables high-performance multidimensional data analysis.
Real-Life Example
A company uses an OLAP system to analyze quarterly sales trends across different regions and product categories. A marketing manager may compare revenue performance by city and season to refine business strategies.
6. Comparison of OLTP and OLAP
| Feature | OLTP | OLAP | | Purpose | Process real-time transactions | Analyze historical data | | Query Type | Simple, frequent transactions | Complex, infrequent analysis | | Data Structure | Normalized | Denormalized | | Performance | Optimized for fast inserts/updates | Optimized for analytical queries | | Use Case | Banking, e-commerce, order processing | Business intelligence, forecasting |
4. Introduction to Schema Concepts
In the field of data warehousing and business intelligence (BI), schemas play a crucial role in organizing and structuring data to enable efficient querying and analysis. A schema defines how data is stored, how tables are related, and how queries interact with the data. The structure of a schema directly influences performance, storage efficiency, and ease of use.
Two of the most common schema models used in data warehousing are the Star Schema and the Snowflake Schema. Both are optimized for analytical queries and reporting, but they differ in terms of structure, complexity, and efficiency.
1. Star Schema
The Star Schema is one of the most widely used and simplest data warehouse schema designs. It gets its name from its structure, where a central fact table is connected to multiple dimension tables, forming a star-like shape.
Key Features of the Star Schema
- Fact Table as the Core
The fact table is at the center of the schema, containing quantitative data such as sales, revenue, or units sold. It includes foreign keys that reference the dimension tables. The fact table holds measurable business metrics that are analyzed.
- The fact table is at the center of the schema, containing quantitative data such as sales, revenue, or units sold.
- It includes foreign keys that reference the dimension tables.
- The fact table holds measurable business metrics that are analyzed.
- Denormalized Dimension Tables
The surrounding dimension tables store descriptive data related to the fact table. Examples of dimensions include Time, Product, Customer, and Location. Data within dimension tables is denormalized, meaning attributes are stored within a single table instead of being split across multiple tables.
- The surrounding dimension tables store descriptive data related to the fact table.
- Examples of dimensions include Time, Product, Customer, and Location.
- Data within dimension tables is denormalized, meaning attributes are stored within a single table instead of being split across multiple tables.
- Simple and Flat Structure
The denormalized approach reduces the number of joins required in queries. This makes queries run faster and is more intuitive for users.
- The denormalized approach reduces the number of joins required in queries.
- This makes queries run faster and is more intuitive for users.
Advantages of the Star Schema
- Easy to understand and use – The simple structure makes it easy for business analysts and non-technical users to run queries.
- Faster query performance – Since dimension tables are denormalized, fewer joins are needed, reducing query execution time.
- Optimized for Business Intelligence (BI) tools – Many BI tools are optimized for star schema structures.
Disadvantages of the Star Schema
- Data redundancy – Because dimension tables are denormalized, some data may be repeated.
- More storage space required – The duplication of data in dimension tables can increase storage requirements.
Real-Life Example
A retail company analyzing sales data might implement a star schema where:
- The fact table stores Total Sales, Units Sold, and Discounts.
- The dimension tables include:
Time – Stores the date, month, and year of each sale. Product – Contains product details such as name, category, and manufacturer. Customer – Holds customer details like name, location, and membership status.
- Time – Stores the date, month, and year of each sale.
- Product – Contains product details such as name, category, and manufacturer.
- Customer – Holds customer details like name, location, and membership status.
Using this schema, a business analyst can efficiently generate reports that show sales trends over time, customer purchasing behavior, and product performance.
2. Snowflake Schema
The Snowflake Schema is an extension of the star schema in which dimension tables are further normalized by breaking them into multiple related tables. This results in a more complex, multi-layered structure that resembles a snowflake.
Key Features of the Snowflake Schema
- Fact Table as the Core
The fact table remains the central table containing business metrics. It maintains relationships with multiple dimension tables.
- The fact table remains the central table containing business metrics.
- It maintains relationships with multiple dimension tables.
- Normalized Dimension Tables
Unlike the star schema, the dimension tables in a snowflake schema are further broken down into multiple tables. For example, instead of a single Product table, there could be:
ProductCategory (stores category names and descriptions) ProductSubCategory (stores subcategories) ProductDetails (stores SKU, price, stock level)
This normalization eliminates redundant data, improving data integrity.
- Unlike the star schema, the dimension tables in a snowflake schema are further broken down into multiple tables.
- For example, instead of a single Product table, there could be:
ProductCategory (stores category names and descriptions) ProductSubCategory (stores subcategories) ProductDetails (stores SKU, price, stock level)
- ProductCategory (stores category names and descriptions)
- ProductSubCategory (stores subcategories)
- ProductDetails (stores SKU, price, stock level)
- This normalization eliminates redundant data, improving data integrity.
- More Complex Structure
The snowflake schema requires more joins when querying the data. Query performance may be slower compared to the star schema due to the increased number of joins.
- The snowflake schema requires more joins when querying the data.
- Query performance may be slower compared to the star schema due to the increased number of joins.
Advantages of the Snowflake Schema
- Reduces data redundancy – Normalization ensures that data is stored efficiently with minimal duplication.
- More efficient storage – Since there is less duplication, the overall storage footprint is reduced.
- Ensures data integrity – The normalized design minimizes inconsistencies and anomalies in the data.
Disadvantages of the Snowflake Schema
- Slower query performance – Queries require more joins, which can slow down execution.
- Increased complexity – More tables make it harder to design, query, and maintain.
Real-Life Example
A retail company using a snowflake schema might break down the Product dimension as follows:
- ProductCategory Table – Stores category information like "Electronics," "Clothing," and "Furniture."
- ProductSubCategory Table – Further categorizes products into groups like "Laptops," "Shirts," and "Chairs."
- ProductDetails Table – Contains detailed product attributes like SKU, brand, and price.
This approach ensures data consistency but requires more complex queries to retrieve product details.
3. Comparison: Star Schema vs. Snowflake Schema
| Feature | Star Schema | Snowflake Schema | | Structure | Simple, flat structure with denormalized dimension tables | Complex, multi-layered structure with normalized dimension tables | | Data Redundancy | Higher, since data is duplicated in dimension tables | Lower, as dimensions are normalized into multiple related tables | | Query Performance | Faster due to fewer joins | Slower due to multiple joins between tables | | Storage Efficiency | Requires more storage due to redundancy | Requires less storage since data is normalized | | Ease of Use | Easier to understand and use for end-users | More complex and harder to maintain | | Data Integrity | Lower due to redundancy | Higher due to normalization | | Ideal Use Case | Suitable for simple queries and quick reports | Best for large datasets requiring high data integrity and storage efficiency |
4. Choosing Between Star and Snowflake Schema
The choice between a star schema and a snowflake schema depends on the specific requirements of the business.
- Use Star Schema when:
Query performance is a priority. Data redundancy and storage costs are not a major concern. The business requires simple and fast reporting.
- Query performance is a priority.
- Data redundancy and storage costs are not a major concern.
- The business requires simple and fast reporting.
- Use Snowflake Schema when:
Data integrity is a priority. Storage efficiency is critical for handling large datasets. The data warehouse contains complex and hierarchical relationships.
- Data integrity is a priority.
- Storage efficiency is critical for handling large datasets.
- The data warehouse contains complex and hierarchical relationships.
5. Introduction to Slowly Changing Dimensions (SCD)
In data warehousing, slowly changing dimensions (SCDs) refer to dimension tables where attributes change over time but not frequently. These changes must be managed to ensure historical accuracy and maintain meaningful analytics.
For example, a customer dimension might contain attributes such as name, address, and phone number. If a customer moves to a new address, the data warehouse must decide how to handle this change—whether to overwrite the previous address, store both the old and new addresses, or maintain a complete history of all address changes. The approach taken depends on business needs and the type of SCD implemented.
SCDs are classified into different types based on how changes in dimension attributes are handled.
1. Type 1: Keep Current Information Only
In Type 1 SCD, the system simply overwrites old data with new data whenever a change occurs. There is no historical tracking, and only the most recent version of the record is stored.
Key Features
- No historical data is retained. When an attribute changes, the old value is replaced.
- Simple implementation since there is no need to maintain historical records.
- Best for non-historical attributes where tracking past values is unnecessary.
Example Scenario
A company maintains a customer dimension that includes customer addresses. If a customer moves to a new address, the old address is replaced with the new one.
Real-Life Example
An e-commerce company updates a customer’s phone number in its customer service database. Since only the latest contact number is needed, previous numbers are not stored.
Advantages
- Simple and easy to implement.
- Uses minimal storage space.
- Queries are faster since no historical joins are required.
Disadvantages
- No way to track historical changes.
- Cannot analyze past trends or changes in customer behavior.
2. Type 2: Keep Historical and Current Information
In Type 2 SCD, both historical and current data are stored. When an attribute changes, a new record is created in the dimension table, while the old record remains unchanged. The validity of each record is tracked using date ranges or active flags.
Key Features
- Maintains full history of changes by creating new records for each update.
- Uses versioning, commonly including fields like effective date, end date, and current flag.
- More complex implementation, requiring ETL (Extract, Transform, Load) processes to handle multiple records per entity.
Example Scenario
A customer dimension stores address information. If a customer moves, a new row is created with the updated address, and the old row is marked as inactive with an end date.
| Customer_ID | Name | Address | Effective_Date | End_Date | Current_Flag | | 1001 | John | 123 Main St | 2020-01-01 | 2022-05-01 | No | | 1001 | John | 789 Oak Ave | 2022-05-02 | NULL | Yes |
Real-Life Example
A banking system tracks changes in customer credit scores. If a customer’s credit score changes, a new row is inserted while retaining previous records for historical analysis.
Advantages
- Retains historical accuracy, useful for trend analysis and reporting.
- Allows point-in-time analysis by providing snapshots of past data.
- Supports better business decision-making by tracking attribute evolution.
Disadvantages
- Increases storage requirements due to multiple records for each entity.
- More complex to implement and maintain.
- Query performance may degrade due to multiple joins.
3. Type 3: Store Only Limited Historical Information
Type 3 SCD keeps only a limited amount of history, typically the previous value and the current value. Instead of storing multiple historical records, a new column is added to store the old value.
Key Features
- Stores only the previous and current values, without keeping a full history.
- Adds additional columns instead of creating new rows.
- Suitable for tracking recent changes without requiring long-term history.
Example Scenario
A customer dimension tracks address changes. Instead of creating new rows, an additional column (previous_address) stores the last known address.
| Customer_ID | Name | Current_Address | Previous_Address | | 1001 | John | 789 Oak Ave | 123 Main St |
Real-Life Example
A job portal tracks job title changes for employees but only keeps one past job title along with the current one.
Advantages
- Easier to implement than Type 2.
- Provides limited history without excessive storage.
Disadvantages
- Cannot track multiple historical changes.
- Not useful for long-term trend analysis.
4. Type 4: Historical Table Approach
In Type 4 SCD, the main dimension table stores only current data, while a separate historical table maintains all previous versions of the data.
Key Features
- The dimension table remains small, containing only the latest records.
- A separate table stores all historical records.
- Queries require joins between the current and historical tables.
Example Scenario
A customer dimension stores only the most recent address, while a historical customer table keeps previous addresses.
Current Customer Table
| Customer_ID | Name | Address | | 1001 | John | 789 Oak Ave |
Historical Customer Table
| Customer_ID | Name | Address | Change_Date | | 1001 | John | 123 Main St | 2022-05-01 |
Real-Life Example
A hospital system tracks patient insurance plans. The active insurance details are stored in the main table, while old insurance records are kept in a historical table.
Advantages
- Keeps the main dimension table lean.
- Reduces query complexity for current data.
Disadvantages
- Requires additional storage for historical tables.
- Queries must join both tables for full historical analysis.
5. Type 6: Hybrid Approach (Combination of Types 1, 2, and 3)
Type 6 combines the features of Type 1, Type 2, and Type 3 to provide flexibility in tracking changes while optimizing performance.
Key Features
- Stores the current value, previous value, and full history.
- Uses both additional columns and new rows.
- Suitable for cases where different attributes require different tracking methods.
Example Scenario
A customer dimension tracks name changes. The table includes:
- The current name (Type 1).
- The previous name in a separate column (Type 3).
- A historical record for each change (Type 2).
| Customer_ID | Current_Name | Previous_Name | Effective_Date | End_Date | | 1001 | John Smith | John Doe | 2022-05-02 | NULL | | 1001 | John Doe | NULL | 2020-01-01 | 2022-05-01 |
Real-Life Example
An HR system tracks employee promotions. The current job title is stored in the main table, the previous title is stored in a separate column, and past records are stored in a historical table.
Advantages
- Provides a comprehensive tracking solution.
- Maintains current, previous, and full historical data.
Disadvantages
- Complex to implement.
- Requires additional storage and processing.
6. Comparison of Slowly Changing Dimensions
| Type | Description | History Stored | Complexity | Use Case | | Type 1 | Overwrites old data | No history | Simple | Status flags, minor updates | | Type 2 | Creates a new record for each change | Full history | Complex | Address changes, sales trends | | Type 3 | Stores previous and current values | Limited history | Moderate | Change in company name, single value changes | | Type 4 | Uses a separate history table | Full history in separate table | Complex | Maintaining lean dimension tables | | Type 6 | Hybrid approach | Full history + previous values | Very complex | Employee promotions, HR systems |