【问题标题】:SSIS incremental data load errorSSIS增量数据加载错误
【发布时间】:2018-11-03 05:04:31
【问题描述】:

我正在尝试执行从临时表 (cust_reg_dim_stg) 到仓库表 (dim_cust_reg) 的增量插入。这是我正在使用的查询。

 insert into dim_cust_reg WITH(TABLOCK)
(
    channel_id
    ,cust_reg_id
    ,cust_id
    ,status
    ,date_created
    ,date_activated
    ,date_archived
    ,custodian_id
    ,reg_type_id
    ,reg_flags
    ,acc_name
    ,acc_number
    ,sr_id
    ,sr_type
    ,as_of_date
    ,ins_timestamp
    )
select channel_id
    ,cust_reg_id
    ,cust_id
    ,status
    ,date_created
    ,date_activated
    ,date_archived
    ,reg_type_id
    ,reg_flags
    ,acc_name
    ,acc_number
    ,sr_id
    ,sr_type
    ,as_of_date
    ,getdate() ins_timestamp

from umpdwstg..cust_reg_dim_stg stg with(nolock)
join lookup_channel ch with(nolock) on stg.channel_name = ch.channel_name

where not exists
(select * from dim_cust_reg dest
    where dest.cust_reg_id=stg.cust_reg_id 
    and dest.sr_id=stg.sr_id
    and dest.channel_id=ch.channel_id )

这里的 channel_id 不在临时表中,而是使用频道查找表 (lookup_channel) 获取的。在运行此查询时,我收到以下错误。

 Violation of PRIMARY KEY constraint 'PK__dim_cust__4A293521A789A5FA'. 
 Cannot insert duplicate key in object 'dbo.dim_cust_reg'.

查询有什么问题? channel_id、sr_id 和 cust_reg_id 形成唯一的组合键。似乎没有数据错误。

【问题讨论】:

  • 主键即channel_id有重复值,可能来自查找通道。检查插入语句中的选择查询

标签: sql sql-server ssis sql-server-2012


【解决方案1】:

您需要排除两个方面的问题:-

在下面的代码中:

join lookup_channel ch with(nolock) on stg.channel_name = ch.channel_name 

与目标维度中的记录相比,暂存表中的传入通道名称可能具有不同的通道名称。

或 可能是因为 NOT EXISTS 条件中的这个连接条件:

and dest.sr_id=stg.sr_id
    and dest.channel_id=ch.channel_id

在这里,当您将暂存数据与目标数据进行比较时,传入的 channel_id 可能会有所不同。因此,建议忽略一次频道 ID 并尝试进行故障排除。将此数据加载到目标中后,您可以了解错误是否是由于 channel_id 的确切原因。

故障排除愉快!

【讨论】:

    【解决方案2】:

    如果表中已经存在重复条目 - cust_regr_dim_stg - 那么 SELECT 查询将生成这两个记录,并尝试将它们插入到 dim_cust_reg 表中。所以在 SELECT 语句中使用 DISTINCT。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-21
      • 2019-05-11
      • 1970-01-01
      • 2020-12-27
      • 2020-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多