{
  "id": "slowly-changing-dimension",
  "title": "Slowly Changing Dimension",
  "lang": "en",
  "source_lang": "en",
  "summary": "A slowly changing dimension is a data-warehousing pattern for managing changes to descriptive attributes while controlling whether historical values are preserved.",
  "category": "computer-science",
  "subcategory": "software",
  "type": "concept",
  "aliases": [
    "SCD",
    "Slowly changing dimensions"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/slowly-changing-dimension/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/slowly-changing-dimension/",
      "json": "https://aiwiki.page/zh/slowly-changing-dimension.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "A slowly changing dimension (SCD) is a dimension in a data warehouse whose descriptive attributes may change over time, together with the modeling techniques used to manage those changes. These techniques determine whether a changed value replaces an earlier value, creates a new historical version, or is stored alongside selected previous values. They allow a warehouse to distinguish questions such as “Which region does this customer belong to now?” from “Which region did this customer belong to when a sale occurred?”\n\n“Slowly changing” describes the traditional contrast between relatively stable descriptive data and frequently arriving transactions; it does not impose a particular update frequency. The same techniques can be applied to attributes that change frequently, although storage and processing costs may make other designs preferable."
    },
    {
      "heading": "Role in dimensional modeling",
      "text": "In dimensional modeling, a dimension table describes entities such as customers, products, employees, or locations. A fact table records measurements or business events, such as sales quantities and revenue, and refers to dimension rows through keys. In a star schema, these relationships provide the context for aggregating and filtering facts.\n\nSuppose a customer moves from the North sales region to the South sales region. Several reporting interpretations are possible:\n\n- All of the customer’s sales, including earlier sales, can be classified under South.\n- Sales before the move can remain classified under North, while later sales are classified under South.\n- Reports can expose both historical and current regional classifications.\n\nThese interpretations answer different business questions. An SCD policy makes the intended interpretation explicit rather than allowing it to emerge accidentally from database updates.\n\nThe policy normally applies at the attribute level, not necessarily to an entire table. A customer dimension might overwrite corrections to a name, preserve historical changes to a sales region, and retain an original acquisition channel permanently."
    },
    {
      "heading": "Development and terminology",
      "text": "SCD terminology is closely associated with the dimensional-modeling methods popularized by Ralph Kimball and subsequent data-warehousing literature. Types 1, 2, and 3 form the core classification; later treatments include Type 0 and additional combinations.\n\nThe type numbers identify storage and update strategies. They are not maturity levels, and a higher number is not inherently better. Terminology for some extended types varies among authors and software products, so an implementation requires a description of its actual behavior rather than just a type number."
    },
    {
      "heading": "Principal types",
      "text": "Type 0: retain the original value\n\nType 0 preserves a value without changing it through the ordinary dimension-update process. Typical examples include an original account-opening date or the customer segment assigned at acquisition.\n\nThis approach deliberately does not represent subsequent changes in that attribute. Exceptional corrections may still be allowed under a separate policy; “retain the original” is a modeling rule, not a technical guarantee that a column can never be edited.\n\nType 1: overwrite the value\n\nType 1 replaces an old attribute value with the new value in the existing dimension row. It does not preserve the overwritten value within that attribute’s dimension history.\n\nFor example:\n\nCustomer key | Customer ID | Region\n501 | C104 | North\n\nAfter a Type 1 update:\n\nCustomer key | Customer ID | Region\n501 | C104 | South\n\nExisting facts that reference customer key 501 now resolve to South. Reports grouped by region may therefore change even though no fact rows have changed.\n\nType 1 is useful when historical values are unnecessary or when an earlier value was an error that should not remain the basis for reporting. It is simple and storage-efficient, but cannot by itself reproduce the overwritten state. A separate audit log or source history may retain that information without making it available through the dimension’s ordinary reporting structure.\n\nType 2: add a historical version\n\nType 2 creates a new dimension row when a tracked attribute changes. Each version normally receives a distinct surrogate key, while a business identifier connects the versions to the same underlying entity.\n\nA common structure includes:\n\n- A surrogate key identifying one version.\n- A business or durable identifier identifying the entity.\n- The descriptive attributes.\n- An effective start timestamp.\n- An effective end timestamp.\n- Optionally, a current-row indicator or version number.\n\nFor example:\n\nCustomer key | Customer ID | Region | Valid from | Valid to\n501 | C104 | North | 2024-01-01 | 2024-07-01\n738 | C104 | South | 2024-07-01 | Open-ended\n\nA sale occurring before 1 July references key 501; a later sale references key 738. Each key can serve as the dimension table’s primary key, with a corresponding foreign key in the fact table.\n\nEffective intervals are often represented as half-open ranges:\n\n\\[\\text{valid\\_from} \\leq t < \\text{valid\\_to}.\\]\n\nThis convention lets one version end exactly when the next begins without assigning the boundary instant to both versions. An open-ended current interval may use a null end value or a designated maximum date, with query logic adjusted accordingly.\n\nType 2 supports historical analysis but increases row counts and loading complexity. Its accuracy depends on the completeness of the captured changes and on correct assignment of facts to versions.\n\nType 3: add an attribute for a previous value\n\nType 3 stores an earlier value in an additional column rather than creating a new row. A dimension might contain current_region, previous_region, and region_change_date.\n\nThis supports a bounded alternative view, such as comparing the current regional structure with the immediately preceding structure. It does not provide unlimited history unless the schema is repeatedly extended, which is generally not its purpose.\n\nType 3 is especially relevant when users need to view the same facts under two explicitly defined classifications rather than reconstruct every state over time."
    },
    {
      "heading": "Extended and hybrid patterns",
      "text": "More elaborate patterns combine these basic approaches.\n\nA mini-dimension separates a group of attributes into another dimension, often to avoid creating a new version of a large main dimension whenever rapidly changing profile attributes change. In Kimball terminology, this is associated with Type 4. Other literature uses “Type 4” for a separate history-table approach, making the convention important to specify.\n\nType 5 combines a mini-dimension with a Type 1 reference from the base dimension to the current profile. Facts can retain the profile applicable to an event, while the base dimension also exposes the current profile.\n\nType 6 combines Type 1, Type 2, and Type 3 ideas. A common design retains version rows and historical attributes while propagating designated current-value attributes across an entity’s versions. This allows historical facts to be grouped by either an event-time classification or a current classification.\n\nType 7 supports both historical and current perspectives through separate access paths, commonly using a version-specific surrogate key and a durable entity key. The durable key identifies the entity across versions, enabling access to its current representation without replacing the historical reference.\n\nThese patterns require clear column names, relationships, and reporting definitions. Otherwise, users can mix current and historical attributes without realizing that the resulting report has changed its temporal meaning."
    },
    {
      "heading": "Loading and temporal correctness",
      "text": "SCD maintenance is commonly performed in extract, transform, load or related warehouse-loading pipelines. A load identifies an entity, compares tracked attributes with stored values, applies the appropriate policy, and assigns dimension keys to incoming facts.\n\nDetecting changes\n\nChanges can be detected through source comparisons, snapshots, modification timestamps, or change data capture. Comparison rules must account for null values, character normalization, numeric precision, and other representation differences.\n\nA hash function can summarize tracked attributes to accelerate comparisons, but consistent encoding and null handling remain necessary. Hash equality is also not an absolute mathematical guarantee that the underlying values are identical.\n\nMaintaining consistent versions\n\nClosing an old Type 2 interval and inserting its replacement should form a consistent operation, often protected by a database transaction. Relevant checks include:\n\n- No overlapping effective intervals for the same entity.\n- No more than one current version when the entity is modeled as having a single current state.\n- Unique version keys.\n- Correct behavior when a load is retried.\n\nGaps between intervals are not always errors: their validity depends on whether an entity is allowed to be inactive.\n\nLate-arriving data\n\nThe time at which a warehouse receives a change may differ from the time when that change became effective.\n\nA late-arriving fact should normally resolve to the dimension version valid at the event time, not automatically to the current version. A retroactive dimension change can require splitting an existing interval and reassigning affected fact references. If historical versions or trustworthy effective dates are unavailable, the warehouse may be unable to reconstruct the correct earlier state.\n\nSome systems create an inferred or placeholder dimension member when facts arrive before their descriptive data. Later enrichment must distinguish filling missing information from recording a genuine business change."
    },
    {
      "heading": "Relationship to other historical techniques",
      "text": "SCD Type 2 resembles versioning in a temporal database, but the concepts are not identical. A typical Type 2 dimension models valid time: when a value applies in the business domain. A system-versioned database commonly records transaction time: when the database stored a version.\n\nA bitemporal model records both. It can distinguish “the region valid on the sale date” from “the region that the warehouse believed was valid when an earlier report was produced.” Ordinary Type 2 history does not automatically preserve both perspectives.\n\nSCD history is also distinct from an event log. An event log records changes or actions, whereas a dimension generally presents entity states suitable for analytical joins. Nor is SCD history equivalent to data backup: backups support recovery, not necessarily convenient temporal analysis."
    },
    {
      "heading": "Design trade-offs and limitations",
      "text": "The central design choice is the meaning of historical reporting. An organizational reassignment may require preservation for event-time analysis, while a corrected spelling may reasonably overwrite older values. Whether a correction should restate previous reports is a business requirement, not something the type number decides.\n\nImportant limitations include:\n\n- Incomplete source history: periodic snapshots may miss multiple changes between observations.\n- Identity instability: recycled or inconsistent business identifiers can incorrectly merge entities or split one entity’s history.\n- Version growth: frequently changing attributes can produce large dimensions and more expensive loading.\n- Query ambiguity: joining historical facts directly to all versions of an entity can duplicate rows and inflate totals.\n- Retention obligations: preserving historical personal attributes can conflict with data privacy and deletion requirements.\n- Limited reproducibility: dimension history alone cannot reproduce an earlier report if facts, calculations, or business rules have also changed.\n\nDocumented temporal semantics, data quality checks, and data lineage are therefore important parts of an SCD implementation, alongside the physical table structure."
    }
  ],
  "links": [
    "data-warehouse",
    "primary-key",
    "foreign-key",
    "change-data-capture",
    "hash-function",
    "database-transaction",
    "data-backup",
    "data-privacy",
    "data-quality",
    "data-lineage"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}