Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

primary key violation for a record that does not exist

$
0
0

Using SQLserver 2008 R2 enterprise edition

I am trying to insert a set of records in a table that has a primary key constraint (clustered key on PKCol1(char(18), PKCol2 int, PKCol3 int).

I get error: 

Msg 2627, Level 14, State 1, Line 809
Violation of PRIMARY KEY constraint 'PK__FactMe__8B063xYX'. Cannot insert duplicate key in object 'myschema.FactMTbl'. The duplicate key value is (200124396123      , 403123, 599123).

I run the following query to check if a record with those values in the primary key column exist, but I get no results.

Select * from myschema.FactMTbl where PKCol1 in ('200124396123' , '403123', '599123')

Select * from myschema.FactMTbl where PKCol1 like '20012439612%'

Select * from myschema.FactMTbl where ltrim(rtrim(PKCol1)) like '20012439612%'

Select * from myschema.FactMTbl where PKCol2 in (200124396123 , 403123, 599123)

Select * from myschema.FactMTbl where PKCol3 in (200124396123 , 403123, 599123)

Why am I getting the primary key violation error, if those records do not exist?

Thanks in advance for your help.




Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>