SQL Server Performance

To copy only the rows that not in the target table

Discussion in 'SQL Server DTS-Related Questions' started by vvkp, Aug 12, 2003.

  1. vvkp New Member

    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
  2. bambola New Member


    INSERT INTO target_table
    SELECT *
    FROM source_table a
    WHERE NOT EXISTS
    (
    SELECT NULL
    FROM target_table
    WHERE a.pk = target_table.pk
    )

    Bambola.
  3. vvkp New Member

    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?
  4. satya Moderator

    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
  5. gaurav_bindlish New Member

    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
  6. gaurav_bindlish New Member

    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
  7. satya Moderator

    ... True, and if the Tlog is important then perform Tlog backup.

    _________
    Satya SKJ
    Moderator
    SQL-Server-Performance.Com

Share This Page