程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> SSAS:基於雪花模型的維度設計

SSAS:基於雪花模型的維度設計

編輯:關於SqlServer

基於雪花模型的維度以下面的 Product 產品與產品子類別,產品類別為例。 DimProduct 表和 DimProductSubcategory 表有外鍵關系,而 DimProductSubcategory 表和 DimProductCategory 表存在 外鍵關系。

測試的維度表與數據 -
USE BIWORK_SSIS
GO
    
IF OBJECT_ID('DimProduct') IS NOT NULL
DROP TABLE DimProduct 
GO
    
IF OBJECT_ID('DimProductSubcategory') IS NOT NULL
DROP TABLE DimProductSubcategory 
GO
    
IF OBJECT_ID('DimProductCategory') IS NOT NULL
DROP TABLE DimProductCategory 
GO
    
SELECT ProductKey,
       ProductAlternateKey,
       ProductSubcategoryKey,
       EnglishProductName,
       StandardCost,
       Color,
       SafetyStockLevel,
       ListPrice,
       Class,
       Size,
       StartDate,
       EndDate,
       [Status],
       ProductAlternateKey + ' (' + CONVERT (Char(10), StartDate, 120) + ')' AS ProductID
INTO DimProduct
FROM AdventureWorksDW2012.dbo.DimProduct
    
SELECT ProductSubcategoryKey,
       ProductSubcategoryAlternateKey,
       EnglishProductSubcategoryName,
       ProductCategoryKey 
INTO DimProductSubcategory
FROM AdventureWorksDW2012.dbo.DimProductSubcategory
    
SELECT ProductCategoryKey,
       ProductCategoryAlternateKey,
       EnglishProductCategoryName
INTO DimProductCategory
FROM AdventureWorksDW2012.dbo.DimProductCategory
    
ALTER TABLE DimProductCategory 
ADD CONSTRAINT PK_CategoryKey PRIMARY KEY CLUSTERED(ProductCategoryKey)
GO
    
ALTER TABLE DimProductSubcategory 
ADD CONSTRAINT PK_SubCategoryKey PRIMARY KEY CLUSTERED(ProductSubcategoryKey)
GO
    
ALTER TABLE DimProduct 
ADD CONSTRAINT PK_Product PRIMARY KEY CLUSTERED(ProductKey)
GO
    
ALTER TABLE DimProduct
ADD CONSTRAINT FK_SubcategoryKey FOREIGN KEY(ProductSubcategoryKey) REFERENCES 

DimProductSubcategory(ProductSubcategoryKey)
    
ALTER TABLE DimProductSubcategory
ADD CONSTRAINT FK_CategoryKey FOREIGN KEY(ProductCategoryKey) REFERENCES 

DimProductCategory(ProductCategoryKey)
    
SELECT * FROM DimProduct 
SELECT * FROM DimProductSubcategory
SELECT * FROM DimProductCategory

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved