简体   繁体   English

如何在 ETL 期间用代理键替换主键?

[英]How to replace primary key with surrogate keys during ETL?

Have a question that is haunting me for some time.有一个困扰我一段时间的问题。

How in practice looks replacing primary keys with surrogate keys during the ETL process?在 ETL 过程中,如何用代理键替换主键? Like what is the workflow - is it just assigning new IDENTITY?就像工作流程一样 - 它只是分配新的身份吗? If so, how about previous values, how to replace existing business keys with newly created ones?如果是这样,以前的值如何,如何用新创建的业务键替换现有的业务键?

In my mind a specific workflow looks like below, but I haven't done it in practice yet:在我看来,一个特定的工作流程如下所示,但我还没有在实践中完成它:

  1. Drop existing PK_Product and FK_Product in DimProduct and FactSales tables.删除 DimProduct 和 FactSales 表中的现有 PK_Product 和 FK_Product。
  2. Set a new IDENTITY column to dimProduct.将新的 IDENTITY 列设置为 dimProduct。
  3. Add new column to FactSales with values from newly created IDENTITY column based on join on previous business key.将新列添加到 FactSales,其值来自基于先前业务键联接的新创建的 IDENTITY 列。
  4. Drop an old ProductKey columns in both tables.删除两个表中的旧 ProductKey 列。
  5. Add constraints for newly created surrogate IDENTITY keys.为新创建的代理 IDENTITY 键添加约束。
  6. Assign reference between tables for future-coming values.为未来的值分配表之间的参考。

But please tell me how you do this in your job and correct me, because I think I'm wrong.但请告诉我你在工作中是如何做到这一点的并纠正我,因为我认为我错了。

Let's take the simplest case where your target dimension is being loaded from a single source system.让我们以最简单的情况为例,您的目标维度是从单个源系统加载的。 The basic steps would be:基本步骤是:

  1. Take the unique identifier for the source system record - normally either the PK or BK获取源系统记录的唯一标识符 - 通常是 PK 或 BK

  2. Use this identifier to lookup the corresponding record in the target dimension - which holds this identifier as well as the SK and other attributes - and return the SK if a record is found in the Dim使用这个标识符在目标维度中查找对应的记录——它包含这个标识符以及 SK 和其他属性——如果在 Dim 中找到记录,则返回 SK

  3. If an SK is found then you are going to perform an Update on the Dim using the SK as the primary identifier如果找到 SK,那么您将使用 SK 作为主要标识符对 Dim 执行更新

    a.一个。 You may also need to perform an insert eg if the Dim is SCD2您可能还需要执行插入,例如如果 Dim 是 SCD2

    b.湾。 If there have been no changes between the source and target record you may decide not to process the source record如果源记录和目标记录之间没有更改,您可以决定不处理源记录

  4. If no SK is found then you will insert a new record into the target Dim, generating a new SK value in one of two main ways:如果没有找到 SK,那么您将在目标 Dim 中插入一条新记录,以两种主要方式之一生成新的 SK 值:

    a.一个。 Using the capabilities of the underlying database, such as sequences, auto-increment columns, etc.使用底层数据库的能力,例如序列、自增列等。

    b.湾。 Using the capabilities of your ETL tool eg a sequence generator使用 ETL 工具的功能,例如序列生成器

These are obviously the logically steps you need to follow.这些显然是您需要遵循的逻辑步骤。 How you actually implement them depends entirely on your ETL/ELT components - so running a merge command in your DB will look very different from an Informatica workflow but "under the covers" both processes are following the same logical steps您如何实际实现它们完全取决于您的 ETL/ELT 组件 - 因此在您的数据库中运行合并命令看起来与 Informatica 工作流非常不同,但“在幕后”这两个过程都遵循相同的逻辑步骤

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

相关问题 维度建模:如何创建没有代理主键的表? - Dimensional Modeling: how to create a table without Surrogate Primary Keys? 如何创建与主代理密钥相对应的父代理密钥? - How do i create a Parent surrogate key that corresponds to the Primary surrogate key? 如何在具有复合外键的数据库上创建代理键? - How do I create a surrogate key on a database with composite foreign keys? 查找表——自然键或代理键作为主键? - Lookup Table -- Natural or Surrogate key as primary key? 主键和代理键之间有什么区别? - What is the difference between a primary key and a surrogate key? 替代键作为复合键上的外键 - Surrogate key as a foreign key over composite keys 代理键需要按自然键排序 - Surrogate Keys need to be ordered by natural key 数据库“密钥/ ID”设计思想,代理密钥,主键等 - Database “key/ID” design ideas, Surrogate Key, Primary Key, etc 代理与自然主键,*特别*在数据仓库中。 这是有争议的吗? - Surrogate vs Natural Primary Keys, *SPECIFICALLY* in a Data Warehouse. Is this debated? 为每个表添加代理键以依赖自然主键是不是很糟糕? - is it bad to add surrogate key to each table in addiction to the natural primary key?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM