[dba-SQLServer] Violation of primary key constraint

John W. Colby jwcolby at colbyconsulting.com
Wed Sep 22 07:47:42 CDT 2004


I built a table that I want to dump records in to.  The source data is the
PK of my big table plus one of two different zip code fields.  Two queries,
all the records - PKs plus ZIP - from any records with a Zip in field A.
The second all the records - PK plus Zip - with any Zip in field B.  Append
query A, append query B.  In access, Query B would append all the records
where there was not a collision with the PKs already in the table.  In SQL
Server the entire second query just fails because of a collision, giving me
a "Violation of primary key constraint, statement terminated".  

As Bill Cosby says in one of his wonderful acts, "brain damaged children".

'Scuse me, I WANT the primary key constraint to prevent records from going
in but I also want those records without a violation to go in.  So how do I
override this brain damaged child and tell it to accept those records that
do not violate the PK constraint?

John W. Colby
www.ColbyConsulting.com 





More information about the dba-SQLServer mailing list