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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:05:28+00:00 2026-05-25T02:05:28+00:00

Hi all i have the following merge sql script which works fine for a

  • 0

Hi all i have the following merge sql script which works fine for a relatively small number of rows (up to about 20,000 i’ve found). However sometimes the data i have in Table B can be up to 100,000 rows and trying to merge this with Table A (which is currently at 60 million rows). This takes quite a while to process, which is understandable as it has to merge 100,000 with 60 million existing records!

I was just wondering if there was a better way to do this. Or is it possible to have some sort of count, so merge 20,000 rows from Table B to Table A. Then delete those merged rows from table B. Then do the next 20,000 rows and so on, until Table B has no rows left?

Script:

MERGE
    Table A AS [target]
USING
    Table B AS [source]
ON
    ([target].recordID = [source].recordID)
WHEN NOT MATCHED BY TARGET
    THEN
        INSERT([recordID],[Field 1]),[Field 2],[Field 3],[Field 4],[Field 5])
        VALUES([source].[recordID],[source].[Field 1],[source].[Field 2],[source].[Field 3],[source].[Field 4],[source].[Field 5]
    );
  • 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-25T02:05:28+00:00Added an answer on May 25, 2026 at 2:05 am

    MERGE is overkill for this since all you want is to INSERT missing values.

    Try:

    INSERT INTO Table_A
    ([recordID],[Field 1]),[Field 2],[Field 3],[Field 4],[Field 5])
    SELECT  B.[recordID],
            B.[Field 1],B.[Field 2],B.[Field 3],B.[Field 4],B.[Field 5]
    FROM Table_B as B
    WHERE NOT EXISTS (SELECT 1 FROM Table_A A
                      WHERE A.RecordID = B.RecordID)
    

    In my experience MERGE can perform worse for simple operations like this. I try to reserve it for when you need varying operations depending on conditions, like an UPSERT.

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

Sidebar

Related Questions

I have the following vba: Data is all text, Rows A - J with
Hi I have a question about Batcher's odd-even-merge sort. I have the following code:
I have a small SQL script that I'm executing with Oracle's SQL*Plus to emulate
I have an MSI file which I include the following merge modules modules: <Merge
I have the following case: All boats have a boat type like shark ,
The rails books and web pages I've been following have all stuck to very
I have following statement for query articles from some sections Article.all(:joins => :sections, :conditions
I have following setup, but when I put 1024 and replace all 512 with
I have the following code to zip all the files and then save it
I have the following Regex to match all link tags on a page generated

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.