I get a violation of primary key constraint error on a single record when I try to insert it to an existing table.
The first time the issue appeared was within a merge statement, but I can reproduce the issue trying to insert the record alone through .
The primary key is on a varbinary(20) value generated from a hashbytes function on the concatenation of the values of approximately 20 column values. The varbinary(20) value I'm trying to insert is not present in the target table and it is only present once in the source table. When I filter on the actual column values, the result is the same; one record in the source and zero records in the target.
The target table has 101 178 878 rows. The primary key is not the clustered index on the table, there is an bigint identity column serving as the clustered index. There are no triggers on the target or the source. The collations are the same all over (Danish_Norwegian_CI_AS). The instance is a SQL Server 2008 R2, Standard Edition.
I'm now totally stuck, and I hope very much someone has some help to offer.
Thank you for reading :-)
This is the value that fails: 0x0571F5F713CF220BB0DB057BBCE7E158CA6F89C0
In the target, the following values are the closest to the one failing. There is no value equal to the one failing.
0x0571F5F1238704E1A9D612F0A1648766B769E2AE 0x0571F5F713CF220BB0DB057BBCE7E158CA6F89C0 --the value that fails 0x0571F608CBE12A007F3DC3736D2F03D90ECCF3F7
EDIT: There are corruption issues in the database causing the unexpected behaviour.
SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID('TargetTableName')
– Ashiltargettable.hashpk
andsourcetable.hashpk
? – Audsley