GeoJul
October 10, 2019, 7:25pm
#1
Hi, I am getting the error message
Violation of … constraint ‘…’. Cannot insert duplicate key in object ‘…’ (Msg 2627)
when I try to insert records into a table using MERGE command.
Actually, the target table which I try to insert records is empty & does not have any records now.
Please tell me why I am getting this error message as no existing records are there, there by preventing duplicate insertion.
yosiasz
October 10, 2019, 8:20pm
#2
The source data itself must have the duplicates. Find out why
1 Like
Either the source data has duplicates - or the MERGE is causing the same row to be inserted/updated multiple times. This can be caused by an invalid join criteria or missing criteria.
yosiasz
October 10, 2019, 9:55pm
#4
Just run the source query and see where there might be duplicates
GeoJul
October 11, 2019, 4:38am
#5
Thanks for the insight. The source query was returning duplicate records. I will use DISTINCT clause & see the output.