To copy only the rows that not in the target table | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

To copy only the rows that not in the target table

Hi friends,
Can anybody put some more light on the topic how to copy only those rows that not in the destination table using DTS Package or Stored Procedure.
Thanks in advance
vvkp

INSERT INTO target_table
SELECT *
FROM source_table a
WHERE NOT EXISTS
(
SELECT NULL
FROM target_table
WHERE a.pk = target_table.pk
) Bambola.
Thanks for your code. Is there will be any performance degradation if we implement this code in DTS package, if the table involves millions of rows?

That you can get information from query execution plan by running at QA.
If the table has millions+ rows then definetly slow performance is expected.
Any issue come back to the forum with details. _________
Satya SKJ
Moderator
SQL-Server-Performance.Com

I prefer running this query in batches of 10,000 so that the chances of errors are reduced. Gaurav
Moderator
Man thrives, oddly enough, only in the presence of a challenging environment- L. Ron Hubbard

Another thing, this saves on the trasaction log file as well.
(in case you are not using FASTLOAD option) A checkpoint in the database between batches will reduce the file size and eventually u’ll land up with smaller log file for the process. Gaurav
Moderator
Man thrives, oddly enough, only in the presence of a challenging environment- L. Ron Hubbard

… True, and if the Tlog is important then perform Tlog backup. _________
Satya SKJ
Moderator
SQL-Server-Performance.Com

]]>