0

我正在导入一个简单的 CSV 文件。我写了一个脚本任务来完成它。我的目的地需要一个主键列,所以我在代码中添加了它。

但现在我开始对Flat File Source做同样的事情。但是,我发现一些 消息来源派生列无法创建 ID 或 Guid 列。

唯一可能的解决方法是在导出时编写 TSQL 语句以添加 Guid 或使用脚本组件。

这是真的吗?派生列转换真的不能创建简单的 ID 或 Guid 列吗?有没有其他方法可以在没有脚本的情况下做到这一点?

4

2 回答 2

2

You can set up the destination table that has an IDENTITY column as PK

You send all of your flat file columns into the table (ignoring the IDENTITY column). The PK field will get incremented automatically during the insert.

于 2013-09-16T13:56:11.803 回答
0

不,Derived Column不能包含将增加/减少值的表达式,并且 PK 需要是唯一的。尽管如此,这是一件非常简单的事情。

创建一个变量User::V_Counter并将其放在Transformation ComponentDataFlow 的末尾。将新的 PK 列添加到 OutputBuffer。编码:

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
   DTS.Variables["V_Counter"].Value = Convert.ToInt32(DTS.Variables["V_Counter"].Value)+1
   ResultBuffer.AddRow();
   ResultBuffer.myPK = DTS.Variables["V_Counter"].Value;
}

映射myPK为目标输入列。您可以在这里轻松地操作您的 PK 格式 - 添加字符串/日期前缀等。

于 2013-09-16T13:24:06.993 回答