结构化的,有固定的模式(schema),查询更高效

以下是每种常见数据仓库模型的具体举例:

1. 星型模型(Star Schema)

  • 示例: 假设我们有一个电商数据仓库,需要分析销售数据。
  • 事实表Sales
Sales_IDDate_KeyProduct_KeyCustomer_KeySales_AmountQuantity
1202301011012012002
2202301011022021501
  • 维度表
  • Date:
Date_KeyDateMonthYear
202301012023-01-0112023
  • Product:
Product_KeyProduct_NameCategory
101LaptopElectronics
  • Customer:
Customer_KeyCustomer_NameRegion
201AliceUSA

2. 雪花模型(Snowflake Schema)

  • 示例: 假设我们继续使用电商数据仓库,但这次我们对维度表进行了规范化。
  • 事实表Sales
Sales_IDDate_KeyProduct_KeyCustomer_KeySales_AmountQuantity
1202301011012012002
  • 维度表
  • Date(同星型模型)
  • Product(规范化,拆分为 ProductCategory):
  • Product:
Product_KeyProduct_Name
101Laptop
  • Category:
Category_KeyCategory_Name
1Electronics
  • Customer(规范化,拆分为 CustomerRegion):
  • Customer:
Customer_KeyCustomer_Name
201Alice
  • Region:
Region_KeyRegion_Name
1USA

3. 星座模型(Fact Constellation Schema)

  • 示例: 假设我们同时分析销售数据和库存数据。
  • 事实表
  • Sales:
Sales_IDDate_KeyProduct_KeySales_AmountQuantity
  • Inventory:
Inventory_IDDate_KeyProduct_KeyStock_Level
  • 共享的维度表(如 ProductDate):
  • Product:
Product_KeyProduct_NameCategory
  • Date:
Date_KeyDateMonthYear

4. 层次模型(Hierarchical Schema)

  • 示例: 假设我们在一个组织的数据仓库中分析员工的层级结构。
    • 员工表(单一表格):
Employee_IDEmployee_NameManager_IDDepartment
1JohnNULLSales
2Alice1Sales
3Bob1Marketing
- 其中,`Manager_ID` 表示员工的上级ID,形成了层次结构。层级关系:
    - `John` 是顶层(无上级),
    - `Alice` 和 `Bob` 的上级是 `John`。

5. 虚拟数据模型(Virtual Data Model)

  • 示例: 假设有一个销售数据表和产品数据表,但用户并不直接存储这些数据,而是通过数据库视图(Virtual View)进行查询。
    • Sales_View(视图):

      CREATE VIEW Sales_View AS
      SELECT s.Sales_ID, s.Sales_Amount, p.Product_Name
      FROM Sales s
      JOIN Product p ON s.Product_Key = p.Product_Key;
    • 用户查询时使用 Sales_View,而不是直接查询物理表。

6. 平面模型(Flat Schema)

  • 示例: 假设我们有一个简单的销售数据表,其中没有维度表,仅将所有数据平铺在一张表中。
    • Sales:
Sales_IDDateProduct_NameCategoryCustomer_NameRegionSales_AmountQuantity
12023-01-01LaptopElectronicsAliceUSA2002
22023-01-01MouseAccessoriesBobUK205

在平面模型中,所有信息都存储在同一个表格中,冗余性高。