简体   繁体   English

数据仓库事实表外键生成

[英]Data warehouse Fact table foreign key Generation

I am pretty new to data warehouse designing.我对数据仓库设计很陌生。 I have a database like below.我有一个如下所示的数据库。 在此处输入图像描述

https://webpages.charlotte.edu/mirsad/itcs6265/group1/domain.html https://webpages.charlotte.edu/mirsad/itcs6265/group1/domain.html

I am planning to create a simple data warehouse like below.我打算创建一个简单的数据仓库,如下所示。

在此处输入图像描述

But the problem I am facing now is I don't have ClientId and LoanId in the Fact table.但我现在面临的问题是我在 Fact 表中没有 ClientId 和 LoanId。 Because in the original database it was lnked via Account table.因为在原始数据库中,它是通过 Account 表连接的。 I am trying to achieve this via SQL server.我正在尝试通过 SQL 服务器来实现这一点。 Can someone show me the direction how to approach this.有人可以告诉我如何解决这个问题。

If you want to create the FactTransaction fact table you don't need the Loan because it represents a fact so Transaction and Loan are two differnt actions like mentioned in the data dictionary:如果要创建 FactTransaction 事实表,则不需要 Loan,因为它表示事实,因此 Transaction 和 Loan 是数据字典中提到的两个不同的操作:

TRANSACTIONS (TRANS) Each record describes one transaction on an account TRANSACTIONS (TRANS) 每条记录描述一个账户的一次交易

LOANS Each record describes a loan granted for a given account贷款 每条记录都描述了为给定帐户授予的贷款

the design can be like below if we follow a separate context for each:如果我们为每个设计遵循单独的上下文,则设计可能如下所示:

Datamart Transaction:数据集市交易:

在此处输入图像描述

Datamart Loan:数据集市贷款:

在此处输入图像描述

The query to populate the FactTransaction is like below:填充 FactTransaction 的查询如下所示:

SELECT T.account_id AS TransactionID, C.client_id AS ClientID,
A.account_id AS AccountID
FROM Transactions AS T
LEFT JOIN Account AS A ON A.account_id=T.account_id
LEFT JOIN Disposition AS D ON A.account_id=D.account_id
LEFT JOIN Client AS C ON C.client_id=D.client_id

AccountID, TransactionID, ClientID represent a composite key to uniquely identify the tuple transaction in a the fact table. AccountID、TransactionID、ClientID 表示一个复合键,用于唯一标识事实表中的元组事务。

The query to populate the FactLoan is like below:填充 FactLoan 的查询如下所示:

 SELECT L.account_id AS LoanID, C.client_id AS ClientID,
A.account_id AS AccountID
    FROM Loan AS L
    LEFT JOIN Account AS A ON A.account_id=A.account_id
    LEFT JOIN Disposition AS D ON A.account_id=D.account_id
    LEFT JOIN Client AS C ON C.client_id=D.client_id

AccountID, LoanID, ClientID represent a composite key to uniquely identify the tuple transaction in a the fact table. AccountID、LoanID、ClientID 表示一个复合键,用于唯一标识事实表中的元组事务。

Do not forget to implement the DimDate.不要忘记实现 DimDate。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM