Kris Krause .NET Meister

"If it is fast and ugly, they will use it and curse you; if it is slow, they will not use it."
- David Cheriton, The Art of Computer Systems Performance Analysis

Tuesday, March 18, 2008

Finding Primary Key Violations

Recently I've been processing lots of legacy DBase files into Sql Server 2005 via SqlBulkCopy.

However, before I import the records (tens of thousands) there is a need to find, then handle the legacy DBase records that will cause a Sql Server primary key violation (if any).

Karen Gayda's solution works like a charm:

http://www.sqlteam.com/article/anticipating-primary-key-violations

IMPORTANT: SqlBulkCopy has a column mapper feature. However, only key columns should be included in select parameter - @vcSelectStatement. If source table columns are named differently than in the target then they must be aliased with the same name as the target. These restrictions were necessary to make the procedure generic.

Labels:

1 Comments:

  • Wow, this stuff is really over my head!! haha But it would be fantastic if we travel together!!
    Keep in touch!
    Sharon and John Flath

    By Blogger Sharon, at 1:06 PM  

Post a Comment

<< Home