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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:20:50+00:00 2026-06-05T14:20:50+00:00

This topic is related to Copy missing rows from one table to another in

  • 0

This topic is related to Copy missing rows from one table to another in sql server with stored procedure but this time the problem is a bit more complex.

I have to tables in different databases (on the same server) that are identical. I need to transfer the data rows from the left database table to the right database table, but I only want to transfer the rows that aren’t in the right database table already.

My table have four primary keys, see image

enter image description here

I’d like to use something like this

insert into [EXTERN_EPI6R2].[dbo].[tblBigTableReference]
select * from [EXTERN].[dbo].[tblBigTableReference]
where (
 pkId not in (select pkId 
  from [EXTERN_EPI6R2].[dbo].[tblBigTableReference]) 
 and PropertyName not in (select PropertyName 
  from [EXTERN_EPI6R2].[dbo].[tblBigTableReference]) 
 and IsKey not in (select IsKey 
  from [EXTERN_EPI6R2].[dbo].[tblBigTableReference])
 and [Index] not in (select [Index] 
  from [EXTERN_EPI6R2].[dbo].[tblBigTableReference])
)

But, that wont work since the stacking of the conditions is wrong in some way.

Im using SQL Server 2008 R2

  • 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-05T14:20:51+00:00Added an answer on June 5, 2026 at 2:20 pm

    Your query is not correct because your various conditions can be matched on different rows.

    insert into [EXTERN_EPI6R2].[dbo].[tblBigTableReference]
    select * from [EXTERN].[dbo].[tblBigTableReference] AS s
    where NOT EXISTS 
    (
      SELECT 1 FROM [EXTERN_EPI6R2].[dbo].[tblBigTableReference] AS d
      WHERE d.pkId = s.pkId 
      AND d.PropertyName = s.PropertyName
      AND d.IsKey = s.IsKey
      AND d.[Index] = s.[Index] -- terrible column name
    );
    

    But this begs the question – why are all four of these columns part of the key? Is pkId not enough? If it isn’t, it sure has a strange and incorrect name.

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

Sidebar

Related Questions

I saw two related questions about this topic - one has an old link
I browsed through all kinds of post related to this topic but the answers
I need some direction related to this topic; maybe I am missing the obvious.
Sorry if this is off topic - but it is certainly programming related .
Note: This is closely related to my other topic here and here , but
Now I know there is some related questions on this topic but this is
All my questions in this topic related to asp.net 2.0 While working on some
The title is my question. I already found a topic related to this here
I have read a lot of related topics here regarding this problem but I
This topic has been covered on this forums, but I haven't found a working

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.