简体   繁体   English

维度表主键转移到事实表不能写值

[英]Transfer of primary keys of dimension table to fact table cannot write values

My problem is understand the relation of primary keys to the fact table.我的问题是了解主键与事实表的关系。

This is the structure I'm working in, the transfer works but it says the values I set as primary keys cannot be NULL这是我正在使用的结构,传输有效,但它说我设置为主键的值不能为 NULL

这是我正在使用的结构,传输有效,但它说我设置为主键的值不能为 NULL

I'm using SSIS to transfer data from a csv file to an OLEDB (SQL server 2019 over SSMS)我正在使用 SSIS 将数据从 csv 文件传输到 OLEDB(SQL server 2019 over SSMS)

The actual problem is where/how I can get the values in the same task?实际问题是在哪里/如何在同一任务中获取值? I tried to do in in two different tasks but then it is in the table one after another ( this only worked when I allowed nulls for the primary keys and can't be a solution I think.)我试图在两个不同的任务中完成,但它一个接一个地出现在表中(这仅在我允许主键为空值时才有效,我认为不能成为解决方案。)

Maybe the problem I have three transfer from the source可能是我的问题从源头三个转

  1. first dimension table第一维表
  2. to second dimension table到第二维表
  3. to fact table.到事实表。 I think the primary keys are generated when I transfer the data to the DB so I think I can't get it in the same task.我认为主键是在我将数据传输到数据库时生成的,所以我认为我无法在同一个任务中获得它。

You are attempting to load the fischspezi fact table as well as the product (produkt) and location (standort).您正在尝试加载 fischspezi 事实表以及产品 (produkt) 和位置 (standort)。 The problem is, you don't have the keys from the dimensions.问题是,您没有维度中的键。

I assume the "key" columns in your dimension are autogenerated/identity values?我假设您维度中的“关键”列是自动生成的/身份值? If that's the case, then you need to break your single data flow into two data flows.如果是这种情况,那么您需要将单个数据流分解为两个数据流。 Both will keep the Flat File source and the multicast.两者都将保留平面文件源和多播。

Data Flow Dimensions数据流维度

This is the existing data flow, minus the path that leads to the Fact table.这是现有数据流,减去通向事实表的路径。

Data Flow Fact数据流事实

This data flow will work to populate the Fact table.此数据流将用于填充事实表。 Remove the two branches to the dimension tables.删除维度表的两个分支。 What we need to do here, is find the translated key values given our inputs.我们在这里需要做的是找到给定输入的翻译后的键值。 I assume produkt_ID and steuer_id should have been defined as NOT NULL and unique in the dimensions but the concept here is that we need to be able to use a value that comes in our file, product id 3892, and find the same row in the dimension table which has a key value of 1.我假设 produkt_ID 和 steuer_id 应该被定义为 NOT NULL 并且在维度中是唯一的,但这里的概念是我们需要能够使用我们文件中的值,产品 ID 3892,并在维度中找到相同的行键值为 1 的表。

The tool for this, is the Lookup Transformation You're going to want 2-3 of those in your data flow right before the destination.用于此目的的工具是查找转换。您将需要数据流中的 2-3 个就在目的地之前。 The first one will lookup produktkey based on produkt_ID.第一个将根据 produkt_ID 查找 produktkey。 The second will find standortkey based on steuer_id.第二个将根据 steuer_id 找到标准密钥。

The third lookup you'd want here (and add back into the dimension load) would lookup the current row in the destination table.您想要的第三次查找(并添加回维度加载)将查找目标表中的当前行。 If you ran the existing package 10 times, you'd have 10x data (unless you have unique constraints defined).如果您运行现有包 10 次,您将拥有 10 倍的数据(除非您定义了唯一约束)。 Guessing here, but I assume sale_id is a value in the source data so I'd have a lookup here to ensure I don't double load a row.在这里猜测,但我假设 sale_id 是源数据中的一个值,所以我会在这里查找以确保我不会双重加载一行。 If sales_id is a generated value, then for consistency, I'd rename the suffix to key to be in line with the rest of your data model.如果 sales_id 是生成的值,那么为了保持一致性,我会将后缀重命名为 key 以与数据模型的其余部分保持一致。

I also encourage everyone to read Andy Leonard's Stairway to Integration Services series.我还鼓励大家阅读 Andy Leonard 的Stairway to Integration Services系列。 Levels 3 &4 address using lookups and identifying how to update existing rows, which I assume will be some of the next steps in your journey.第 3 级和第 4 级地址使用查找并确定如何更新现有行,我认为这将是您旅程中的一些后续步骤。

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

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