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
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.