troubleshooting Question

Need to merge 3 large tables into one Table in SQL server

Avatar of Charles Baldo
Charles BaldoFlag for United States of America asked on
Microsoft SQL Server 2005Microsoft SQL Server
2 Comments1 Solution227 ViewsLast Modified:
Hello

I need to merge three tables into one.  They all have the exact same structure.

Table_A_original
Table_A_Archive_1
Table_A_Archive_2

Then a target table new_TABLE_all

They were supposed to be archived over two new tables and when it happened the records in Table_A_original that were Archived were suppose to be removed.  Some/many were not removed.   I need to rebuild into one table now. the document_id column is the primary key and can be searched. The tables have over 100,000 million records. So I want to be as efficient as possible.

Something like this:???

insert into new_TABLE_all
(
    document_id,
    doc_filename
)
SELECT
    document_id,
    doc_filename
FROM
     Table_A_original where document_id not in  (select document_id from  new_TABLE_all) --- (There must be more efficient way)

then repeat for Archive1 and Archive2

Note:s    document_id is an identity id and is primary key
                Database is old SQL 2005, job is migrating out.

Thank You
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros