Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 3rd, 2004, 06:09 AM
Authorized User
 
Join Date: Mar 2004
Location: Amman, , Jordan.
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,
Reply With Quote
  #2 (permalink)  
Old March 3rd, 2004, 06:32 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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
Reply With Quote
  #3 (permalink)  
Old March 3rd, 2004, 06:38 AM
Authorized User
 
Join Date: Mar 2004
Location: Amman, , Jordan.
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
Reply With Quote
  #4 (permalink)  
Old March 3rd, 2004, 06:48 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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
Reply With Quote
  #5 (permalink)  
Old March 3rd, 2004, 06:53 AM
Authorized User
 
Join Date: Mar 2004
Location: Amman, , Jordan.
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
Reply With Quote
  #6 (permalink)  
Old March 3rd, 2004, 07:06 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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
Reply With Quote
  #7 (permalink)  
Old March 4th, 2004, 04:09 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cairo, , Egypt.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:00 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.