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 8193805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:36:32+00:00 2026-06-07T04:36:32+00:00

I’m having problems with a table copy erroring due to a primary key constraint

  • 0

I’m having problems with a table copy erroring due to a primary key constraint when the primary key is on the new table. In doing some investigation by not setting a primary key I was able to find a duplicate row in my source table, still unsure how it got in there but what I’m more curious about is the rest of what I found.

Here goes:

I have a SQL query that selects the full table and returns the following:

SELECT *
 FROM search_term_suggest
 order by search_term

you can see the value is duplicated and I had to scroll through the table to find it.

SQL Results

But when I limit my query to:

SELECT *
 FROM search_term_suggest
 where search_term = 'b'

you can see it filters out the first value. There are no triggers on the database or anything I can see that would limit the select query.

SQL Results with "where" clause added

I’m running SQL 2008 r2. Any help is greatly appreciated. The database I’m copying the table to is a SQL 2000 database and when selecting using the same queries as above I get the results I would expect.

EDIT: search_term is a varchar(100), search_term_suggest is a table not a view.

  • 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-06-07T04:36:34+00:00Added an answer on June 7, 2026 at 4:36 am

    My guess: search_term is a CHAR/NCHAR and has trailing spaces (or trailing spaces are being considered for other reasons). Try:

    WHERE RTRIM(search_term) = 'b';
    

    You may also need to eliminate tabs/carriage returns, which aren’t affected by trim operations.

    WHERE LTRIM(RTRIM(REPLACE(REPLACE(REPLACE(search_term,
      CHAR(9), ''), CHAR(10), ''), CHAR(13), ''))) = 'b';
    

    Note that both of the above queries preclude using an index, so if there is an index on search_term you should probably rebuild it after changing the column to varchar or nvarchar and making sure that padding settings and whitespace aren’t causing the problem.

    Other guesses: as @Dems points out, check the length of both columns on the first query. Also try changing your where clause to the following, for investigation purposes only:

    WHERE search_term LIKE 'b%'
      AND LEN(search_term) > 1;
    

    If you get any result there, then you can say:

    DECLARE @val VARCHAR(100), @i INT;
    
    DECLARE c CURSOR LOCAL STATIC READ_ONLY FAST_FORWARD 
      FOR SELECT search_term FROM dbo.search_term_suggest
      WHERE search_term LIKE 'b%'
        AND LEN(search_term) > 1;
    
    OPEN c;
    
    FETCH NEXT FROM c INTO @val;
    
    WHILE @@FETCH_STATUS = 0
    BEGIN
      SET @i = 1;
      PRINT '-----' + @val + ' (' + RTRIM(LEN(@val)) + ')';
      WHILE @i <= LEN(@val)
      BEGIN
        PRINT SUBSTRING(@val, @i, 1) + ' = ' + ASCII(SUBSTRING(@val, @i, 1));
        SET @i = @i + 1;
      END
    
      FETCH NEXT FROM c INTO @val;
    END
    CLOSE c;
    DEALLOCATE c;
    

    This will help you troubleshoot what is in that column aside from the b – it may be whitespace you haven’t checked for (e.g. a tab or carriage return) or other non-printing characters.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

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.