简体   繁体   English

更新和删除事实表中的记录

[英]Update and delete records in the fact table

I have a fact table with five dimension tables associated to it.Typically, the fact table contains the surrogate keys of each dimension and has no business/surrogate key. 我有一个与五个维度表关联的事实表,通常情况下,事实表包含每个维度的代理键,并且没有业务/代理键。 I am trying to load the fact table with data resulted of the staging fact table ieInsert new records. 我正在尝试将事实表的数据加载到事实表中,即插入新记录。 However, I notice the fact table can also handle other operations such as Update or Delete on data. 但是,我注意到事实表还可以处理其他操作,例如对数据进行更新或删除。 A conditional split was used in the SSIS Package for this purpose to check if all surrogate keys are 0 then make the new insert. 为此,在SSIS程序包中使用了条件拆分来检查是否所有代理键都为0,然后进行新插入。 My question is, Can I use the surrogate keys in terms of Update or Delete? 我的问题是,我可以在更新或删除方面使用代理键吗?

I made an insert on the fact table just to give an idea of how the data will look like. 我在事实表上进行了插入,只是为了了解数据的外观。

在此处输入图片说明

The answer is yes, you can. 答案是可以的。 BUT, will there be a situation where one employee sold the same product, from the same supplier, to the same customer, on the same day? 但是,是否有可能某个员工在同一天从同一供应商向同一客户出售同一产品? Perhaps a different order on the same day? 也许同一天的订单不同? (this is based on the data you present in the question) (这是基于您在问题中提供的数据)

If all the surrogate keys together can uniquely identify a record, update fact records to your hearts content. 如果所有代理键都可以唯一地标识一条记录,则将事实记录更新为您的内心内容。 But, if that is not the case, you could end up updating records when you do not intend to update. 但是,如果不是这种情况,您可能会在不想更新时最终更新记录。

I tend to include an order number in the fact tables I design to help avoid that situation, but you may not have that in your actual fact tables. 我倾向于在我设计的事实表中包括一个订单号,以帮助避免这种情况,但实际的事实表中可能没有。 Including the order number is a pattern referred to a degenerate dimension in the fact table. 包括订单号的是在事实表中称为退化维的模式。 I have found it to be pretty handy. 我发现它非常方便。

Anyway, the answer is the same. 无论如何,答案是一样的。 You can update fact records based on surrogate keys, as long as all of them together can uniquely identify the row(s) you want to update. 您可以基于代理键更新事实记录,只要它们一起可以唯一标识要更新的行即可。

Don't throw caution to the wind, be sure your data warehouse is designed such that you can do this if you need to. 不要大惊小怪,请确保您的数据仓库设计成可以在需要时执行此操作。 Being able to do in place updates of facts can be nice, versus delete and replace, in that there could be fewer steps in the ETL process. 与删除和替换相比,能够就地更新事实可能会更好,因为ETL流程中的步骤可能更少。

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

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