This document introduces some basic concepts of data tables.
In a dimension model, a dimension table describes an entity relevant to your business and analytics requirements. Generally speaking, a dimension table represents the content you model. The content can be products, people, places, or any other concepts, including date and time. To easily identify dimension tables, you typically need to prefix their names with d_ or Dim_.
This document takes the dimension table d_Salesperson as an example, as shown in the following figure.
Definition: A surrogate key is a unique identifier automatically generated by the data warehouse system. It is used to identify each row in a dimension table.
Function:
Stability: Since the values of the surrogate key are assigned by the system, they remain unaffected by business changes and are therefore more stable.
Performance Advantage: The surrogate key values are sequentially incremented or randomly generated numbers, which improves database indexing performance and enhances query efficiency.
Advantage:
Flexibility: The system can manage unique identifiers independently, thereby reducing the complexity of maintaining consistency across tables and associations when business changes occur.
Maintainability: Since surrogate key values are unaffected by external business data, maintenance becomes significantly simpler.
Applicable Scenario
Dimension Table: Surrogate keys are used in dimension tables to identify each data record.
Association: When you associate dimension tables with fact tables, surrogate keys serve as association fields, enabling more efficient association.
In this example, Salesperson_SK serves as the surrogate key.
As a crucial concept in the dimensional model, the natural key is the counterpart to the surrogate key. The natural key is used as the unique identifier for each record in a dimension table based on the business attribute of the data. The features of the natural key are as follows:
Definition: The natural key is used as the unique identifier for each record in a dimension table based on the business attribute of the existing data.
Business Association: The natural key, which corresponds to the attribute of the business entity, directly reflects the relationship in the real business world.
Understandability: The natural key is typically meaningful to business analysis, enabling business users to better understand data.
Business Understandability: Since the natural key derives its values from the existing data, it is easier for business users to understand and use.
Real-World Business Representation: The natural key directly reflects the business entity, providing a more intuitive representation of the data model.
Limitation:
Instability: Natural keys may be unstable as they can be affected by business changes in some cases.
Complexity: Natural keys may increase the complexity of maintaining consistency across tables and associations when you perform business operations, such as changing, merging, or splitting, on data.
Clarity of Business Entities: The natural key is suitable for the business entity with a clear and stable business identifier.
Better Understandability: The natural key improves understandability when you tend to identify records through business attributes.
In this example, EmployeeID serves as the natural key.
Other dimension tables can reference a foreign key, and their presence in a dimension table is a special case. It indicates that the table is related to another dimension table.
In this example, SalesRegion_FK serves as the foreign key.
The dimension table in this example also contains dimension attributes, for example, the FirstName column. Dimension attributes provide context to the numeric data stored in related fact data tables. They are typically text columns that are used in analytic queries to filter and group data, but not to be aggregated themselves. Some dimension tables contain a few attributes, while others contain many attributes.
Historical tracking attributes are optional based on your need to track specific changes as they occur in the source system. They allow storing values to support the primary role of a data warehouse, which is to describe the past accurately. Specifically, these attributes store historical context as the ETL process loads new or changed data into the dimension.
Audit attributes are optional but recommended. They allow you to track when and how dimension records were created or modified, and they can include diagnostic or troubleshooting information generated during ETL processes. For example, you may want to track who (or which processes) updated a row, and the update time. Audit attributes can also help diagnose a challenging problem, for example, when an ETL process stops unexpectedly.
Generally, the most useful and versatile dimensions in a dimension model are big, wide dimensions. The dimension supports the required filtering, grouping, and accurate historical analysis of fact data.
Big dimensions may be sourced from multiple source systems. In this case, dimension processing requires you to combine, merge, deduplicate, and standardize the data, and assign surrogate keys.
By comparison, some dimensions are small. They might represent lookup tables that contain only several records and attributes. Generally, these small dimensions store category values related to transactions in fact data tables, and they're implemented as dimensions with surrogate keys to associate with the fact records.
Commonly, dimension columns can generate hierarchies. Hierarchies enable you to view data at distinct levels of summarization. For example, the initial view may show the yearly sales amount, and you can drill down into the data to view quarterly and monthly sales amounts.
The following three methods are available to store a hierarchy in a dimension:
Columns from a single, denormalized dimension
A snowflake dimension, which comprises multiple related tables
A parent-child (self-referencing) relationship in a dimension
Balanced hierarchies are the most common type of hierarchy. A balanced hierarchy has the same number of levels. A common example of a balanced hierarchy is a calendar hierarchy in a date dimension that comprises levels for year, quarter, month, and date.
For example, the balanced hierarchy of the store area can include two levels, namely Province and City, as shown in the following figure.
Levels of a balanced hierarchy are either based on columns from a single, denormalized dimension, or from tables that form a snowflake dimension. When based on a single, denormalized dimension, the columns that represent the higher levels contain redundant data.
For balanced hierarchies, fact data always relate to a single level of the hierarchy, which is typically the lowest level. In this way, the fact data can be aggregated (summarized) to the highest level of the hierarchy. Fact data can relate to any level, which is determined by the granularity of the fact table. For example, the sales fact table may be stored at the date level, while the sales target fact table can be stored at the quarter level.
Unbalanced hierarchies are a less common type of hierarchy. An unbalanced hierarchy has levels based on a parent-child relationship. For this reason, the number of levels in an unbalanced hierarchy is determined by the dimension rows instead of specific dimension table columns.
A common example of an unbalanced hierarchy is an employee hierarchy where each row in an employee dimension relates to a report manager row in the same table. In this case, any employee can be a manager with reporting employees. Certainly, some branches of the hierarchy will have more levels than others.
The following figure describes an unbalanced hierarchy. It comprises four levels, and each member in the hierarchy is a salesperson. Salespeople have a different number of superiors in the hierarchy according to who they report to.
Other common examples of unbalanced hierarchies include material lists, company ownership models, and general ledger.
For unbalanced hierarchies, fact data always relate to the dimension granularity. For example, the sales fact data table relates to different salespeople, who have different reporting structures. The dimension table will have a surrogate key (named Salesperson_SK) and a foreign key ReportsTo_Salesperson_FK, which references the primary key column. Each salesperson without anyone to manage is not necessarily at the lowest level of any branch of the hierarchy. When they're not at the lowest level, a salesperson might sell products and have reporting salespeople who also sell products. Therefore, you must consider the individual salesperson and all their subordinates for fact data summarization.
Querying parent-child hierarchies can be complex and slow, especially for large dimensions. While the source system may store relationships as parent-child, you are advised to naturalize the hierarchy. In this example, naturalization means to transform and store the hierarchy levels in the dimension as columns.
Ragged Hierarchy
Sometimes a hierarchy is ragged because the parent level of a member in the hierarchy is not immediately above the member. In these cases, missing level values will repeat the value of the parent level.
Take a balanced geography hierarchy as an example. A ragged hierarchy exists when a country/region has no states or provinces. For example, New Zealand has neither states nor provinces. Therefore, when you insert the value New Zealand into the CountryRegion column, you also need to insert the value into the StateProvince column in the same row.
Fact data tables almost invariably store measures at the specific time. To analyze data by date (which may also be time), there must be calendar (date and time) dimensions.
Generally, a source system does not have calendar dimension data, so the data must be generated in the data warehouse. Typically, it can be generated once. If the data is a calendar dimension, you can extend it with future dates as needed.
Date Dimension
The date (or calendar) dimension is the most common dimension used for analysis. It stores one row per date, and it can meet the common requirement to filter or group data by specific periods of dates (such as years, quarters, or months).
A date dimension should not include a granularity level that extends to time of day. If specific time of day analysis is required, you need to have both a date dimension and a time dimension. Fact data tables that store time of day fact data should have two foreign keys, each corresponding to a dimension.
The natural key of the date dimension should be of the date type. The surrogate key should store the date as an integer in the YYYYMMDD format. This is the only accepted exception to the general rule that surrogate keys convey no meaning, because in the case of date (and time) dimensions, the surrogate key is meaningful and human-readable.
When the dimension is used to relate to fact data at a higher granularity level, the first date of the date period in the fact data table can be used. For example, a sales target fact table that stores quarterly salespeople targets will store the first date of the quarter in the date dimension. An alternative approach is to create key columns in the date table.
The dimension should be populated with the known range of dates used by all fact data tables. It should also include future dates when the data warehouse stores fact data about targets, budgets, or forecasts. As with other dimensions, the date dimension can include rows that represent missing, unknown, N/A, or error information.
Time Dimension
Fact tables need to be stored at a point in time (for example, the specific time of a day). In this case, a time (or clock) dimension is created. It can be at the granularity level of minutes (24 x 60 = 1,440 rows) or even seconds (24 x 60 x 60 = 86,400 rows). Other possible granularity levels include half-hour or hour intervals.
The natural key of a time dimension should be of the time type. The surrogate key can be in an appropriate format, for example, the HHMM or HHMMSS format, and store meaningful and human-readable values.
When a dimension attribute must store multiple values, you need to design a multi-value dimension. You implement a multi-value dimension by creating a bridge table (sometimes called a join table). A bridge table stores the N-to-N relationship between entities.
Assume that there is a salesperson dimension, and that each salesperson is assigned to one or possibly more sales regions. In this case, it makes sense to create a sales region dimension. This dimension stores each sales region only once. A separate table, known as the bridge table, stores a row for each salesperson and sales region relationship. Physically, there is a 1-to-N relationship from the salesperson dimension to the bridge table, and another 1-to-N relationship from the sales region dimension to the bridge table. Logically, there is an N-to-N relationship between salespeople and sales regions.
A degenerate dimension can occur when the dimension is at the same granularity level as the related fact data. A common example of a degenerate dimension is a sales order number dimension that relates to a sales fact table. It's an accepted practice not to copy this data to create a separate dimension table.
The following figure describes a degenerate dimension Sales Order based on the SalesOrderNumber column in a sales fact data table.
When a dimension is referenced multiple times in a fact data table, the dimension is known as a role-playing dimension.
For example, when a sales fact data table has order date, ship date, and delivery date dimension keys, the date dimension relates in three ways. Each way represents a distinct role, yet only one actual date dimension exists.
The following figure describes a fact data table. The Sales dimension is a role-playing dimension because the dimension is related twice to the fact data table as the Contracted Sales dimension and the Sales Opportunities dimension.
滑鼠選中內容,快速回饋問題
滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。
不再提示
10s後關閉
Submitted successfully
Network busy