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

  • Home
  • SEARCH
  • 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 4117790
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:52:42+00:00 2026-05-20T22:52:42+00:00

I am assuming this is the most common scenario with everyone who is working

  • 0

I am assuming this is the most common scenario with everyone who is working with SQL Server.

Scenario:

I have these tables tabSRC_A(id,date,data1), tabSRC_B(id,Date,data2) and tabDEST

Now my task is to get the data from tableSRC_A, tableSRC_B apply some filtering and cleanup on them and insert them into tabDEST.

I am doing this using the following code

insert into tabDest(id, Date, Data1, Data2)
   Select id, date, Data1, Data2 
   from tabSRC_A A 
   inner join tabSRC_B B on A.id = B.id and A.date = B.date
   where not exists 
             (select * from tabDest Dest 
              where Dest.id = B.id and Dest.date = B.date)

and I am updating if already exists

Is this the best solution for this operation?

The size of the tables are 10 million rows each

I was also thinking about creating a view with surrogate key and perform a check based on the id instead of checking every row using the above method

Something like this

 insert into tabDest(id, Date, Data1, Data2)
    Select id, date, Data1, Data2 
    from view_Created_From_TabA_TabB_adding_a_SurrogateKey_Kid SV
    where SV.Kid > select (max(id) from tabDest) 

I am assuming this would be much faster.

Please guide me with any suggestions you have.

(I’m using SQL Server 2000, I know its very old)

  • 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-20T22:52:42+00:00Added an answer on May 20, 2026 at 10:52 pm

    Have you tried a LEFT join to detect not exists?

    insert into tabDest(id, Date, Data1, Data2)
       Select id, date, Data1, Data2 
       from tabSRC_A A 
       inner join tabSRC_B B on A.id = B.id and A.date = B.date
       LEFT JOIN tabDest Dest 
       ON Dest.id = B.id and Dest.date = B.date
    WHERE
       Dest.id is null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am missing this DLL reference in c:\program files\SQL Server\90\Tools\Binn. I'm assuming that this
Assuming I have this HTML structure: <ul class='menu'> <li> <div></div> <div> <div></div> <div> <a
Assuming that I have this: enum { A = 0x2E, B = 0x23, C
Assuming I have a function like this my_method(const vector<const T*> & param); I wonder
Assuming I have a JavaScript function like this... function Object1() { this.var1; this.var2; this.var3;
I have an InnoDB based schema with roughly 100 tables, most use GUID/UUID's as
Note: This is the opposite direction to most similar questions! I have an iPhone
Assuming this table is ordered by date id | date | customer 3 |
I have been trying to get this to work for most of the day
I have a question and i suppose this is trivial for most around here.

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.