title: Better way to check if the data already exists and insert
body: <p>Hi all I have the following SQL Server 2008 script that will check if a row already exists in <code>Table A</code> and if it doesn't insert the data from <code>Table B</code>. </p>
  
  <p>This was working nicely until <code>Table A</code> started to fill up with a lot of data. We currently have 30 million rows in this table and this will continue to grow to a predicated 70 million rows. </p>
  
  <p>The problem if this is taking far too long and is affecting other processes. Just wondering if there is a better way to check if a row already exists in a table. Just to add as well this is all done using an SSIS.</p>
  
  <p>Script:</p>
  
  <pre><code>INSERT INTO TABLE A ([recordID],Field 1, Field2, Field 3, Field 4, Field 5) 
      SELECT 
          [TABLE B].[recordID],[TABLE B].[Field 1], [TABLE B].[Field2], 
          [TABLE B].[Field 3], [TABLE B].[Field 4], [TABLE B].[Field 5] 
      FROM TABLE B AS TABLE B 
      LEFT OUTER JOIN TABLE A AS TABLE A ON [TABLE B].[recordID] = [TABLE A].[recordID] 
      WHERE [TABLE A].[recordID] IS NULL
  </code></pre>