Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6854487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:38:21+00:00 2026-05-27T01:38:21+00:00

I’m trying out the BCP utility on SQL Server 2008 Express. I don’t think

  • 0

I’m trying out the BCP utility on SQL Server 2008 Express. I don’t think that what I’m trying to do could be more trivial, but still I’m getting a primary key violation when trying to insert two rows into an empty table.

Here is the table DDL:

CREATE TABLE [dbo].[BOOKS](
    [BOOK_ID] [numeric](18, 0) NOT NULL,
    [BOOK_DESCRIPTION] [varchar](200) NULL,
CONSTRAINT [BOOKS PK] PRIMARY KEY CLUSTERED 
(
[BOOK_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF,     ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

Here is the BCP format file:

10.0
2
1       SQLNUMERIC          0       3     "\t"     1     BOOK_ID                              ""
2       SQLCHAR             0       0     "\r\n"   2     BOOK_DESCRIPTION                     Modern_Spanish_CI_AS

and here is my input file:

101 BOOK_ABC_001<CR><LF>
102 BOOK_ABC_002<CR><LF>

finally here is the command I run:

bcp Database.dbo.BOOKS in books.txt -T -f BOOKS-format.fmt

and here is the error I get:

Starting copy...
SQLState = 23000, NativeError = 2627
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Violation of PRIMARY KEY  constraint 'BOOKS PK'. Cannot insert duplicate key in object 'dbo.BOOKS'.
SQLState = 01000, NativeError = 3621
Warning = [Microsoft][SQL Server Native Client 10.0][SQL Server]The statement has been terminated.

BCP copy in failed

Now, BCP succeeds if I use an input file with a single line. In this case, the BOOK_ID column gets assigned a value of 0. So it seems that the first field in my input file is being ignored, and 0 is being used as the value for BOOK_ID for all the rows, which would explain the PK violation error.

So the question is, what is wrong in my format or input files that causes the first column to be ignored?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:38:22+00:00Added an answer on May 27, 2026 at 1:38 am

    I’ve never seen a primary key column with datatype DEC, not sure if decimals work. I’ve always used integer.
    BUT what i think the problem is the PK column doesn’t have identity set, so it’s not auto incrementing when it adds a new row. In your table create code, replace:

    [BOOK_ID] [numeric](18, 0) NOT NULL,
    with
    [BOOK_ID] [int] IDENTITY(1,1) NOT NULL,

    Cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.