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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:52:13+00:00 2026-05-15T10:52:13+00:00

I have two identical tables in two different databases with the same data but

  • 0

I have two identical tables in two different databases with the same data but they have different primary keys, I need to update these so they have the same key, so what I did was making sure that none of the tables had any key in common and that there were no duplicates

UPDATE db1.dbo.Table
SET db1.dbo.Table.pcol = rightPcol.pcol
FROM db1.dbo.Table
JOIN db2.dbo.Table AS rightPcol ON db1.dbo.Table.2ndIdent = db2.dbo.Table.2ndIdent

this however results in “Violation of PRIMARY KEY Constraint. Cannot insert duplicate key in object”

when adding a where clause to not update any db1 pcol value that existed in the db2 pcol it didn’t update anything at all, it does look like it tries to update with the primary key in db1 instead of db2.

any and all help is greatly appreciated!

//fixed minor spelling error 🙂

  • 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-15T10:52:14+00:00Added an answer on May 15, 2026 at 10:52 am

    To be honest there isn’t much to say – the error message pretty much describes what is it wrong.

    You are trying to update a PK Column to a value that already exists.

    I would double check to make sure that

    1. by joining on 2ndIdent you are not creating any duplicates.
    2. there really aren’t any duplicates in the tables on DB1 and
      DB2

    Your SQL looks fine so it must be an issue with the data.

    To check for duplicates you could use something like this:

    Select 2ndIndent
    From Table
    Group By 2ndIdent
    Having Count(2ndIndent) > 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 512k
  • Answers 512k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, basically. Expression trees are immutable, and contain full member… May 16, 2026 at 5:39 pm
  • Editorial Team
    Editorial Team added an answer Assuming you are not using the validate plugin and all… May 16, 2026 at 5:39 pm
  • Editorial Team
    Editorial Team added an answer Hey Jonesy, I think this page explains it better than… May 16, 2026 at 5:39 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have two tables in my database, table1 and table2. They are identical. But
I have two files with identical code (it is the code they mention here:
I have two websites that have an almost identical database schema. the only difference
I have a data structure something like this: typedef struct tagSUB_DATA { double measuredValue;
I have two websites that post news information. I just got a request to
I've got an ASP.NET MVC (VB) project with two models that represent two different
I have an interesting problem, that i am sure has a simple answer, but
I have two 3GB text files, each file has around 80 million lines. And
Here’s a problem I’ve really been struggling with. I need to merge two sorted
I'm trying to write a stored procedure to copy a subset of data from

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.