Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2004, 06:09 AM
Authorized User
 
Join Date: Mar 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to deyakhatib
Default Bulk insert

Hi all,
I am trying to use bulk insert and to overwrite the primary keys in the table(destination) with the ones in the text file (source), I am setting the MAxErrors option to 9999, but I am always getting the following error:
"Violation of PRIMARY KEY constraint 'PK_Testingbulk'. Cannot insert duplicate key in object 'Testingbulk'.
The statement has been terminated."

I dont want this statment to be cancelled even if there is errors, and i think maxerror option is the way to do that but its not working.

thanx in advance.
Regards,
 
Old March 3rd, 2004, 06:32 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

How are you running the insert? Are you setting the KEEPIDENTITY flag?



--

Joe
 
Old March 3rd, 2004, 06:38 AM
Authorized User
 
Join Date: Mar 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to deyakhatib
Default

Hi,
there is no identity columns in the table the only constraint is an integer primary key, and I want to replace the whole row of a primary key in the table with the same primary key coming from the text file, the insert is being called from a VB.Net code when a file is generated.

Regards,


Quote:
quote:Originally posted by joefawcett
 How are you running the insert? Are you setting the KEEPIDENTITY flag?



--

Joe
 
Old March 3rd, 2004, 06:48 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

As I understand it MaxErrors only means the procedure carries on after errors, it doesn't let you break constraints. Can you show your BULK INSERT query and your source and target table structure?

--

Joe
 
Old March 3rd, 2004, 06:53 AM
Authorized User
 
Join Date: Mar 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to deyakhatib
Default

As I know also if I have a duplicate key it should be considered as error and it should be skipped and the statment should complete normally, I am testing it on a simple table with 2 columns integer(PK)and nvarchar(2), my statment is
"BULK INSERT test.dbo.[testingbulk]
   FROM 'c:\bulk.txt'
   WITH
      ( datafiletype = 'char',
         FIELDTERMINATOR = ',',
         maxerrors = 1000,
     KEEPIDENTITY
      )"

thanx,

Quote:
quote:Originally posted by joefawcett
 As I understand it MaxErrors only means the procedure carries on after errors, it doesn't let you break constraints. Can you show your BULK INSERT query and your source and target table structure?

--

Joe
 
Old March 3rd, 2004, 07:06 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Jus read the documentation again, seems MAXERRORS does not apply to constraint checks. I'll try to experiment a bit more.

--

Joe
 
Old March 4th, 2004, 04:09 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

i think you have to remove temperory pk constraint , and all other constraints to avoid all errors and for fast copying and check for these constraints after copying, and redo relations.

Ahmed Ali
Software Developer





Similar Threads
Thread Thread Starter Forum Replies Last Post
Bulk Insert snufse SQL Server 2000 9 December 17th, 2007 07:53 AM
BULK INSERT FOR ARRAY MathLearner Beginning VB 6 4 September 28th, 2007 07:18 AM
bulk insert hymavathy_kr VB Databases Basics 1 May 17th, 2007 07:47 AM
BULK INSERT NULL(s) nathansevugan SQL Server 2000 2 November 29th, 2005 01:11 AM
Bulk Insert luma SQL Server DTS 1 July 13th, 2005 01:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.