Я пытаюсь выполнить инкрементную вставку из промежуточной таблицы (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 формируют уникальную комбинацию клавиш.Кажется, что нет ошибки данных.