title: Insert into table when one value not exist in another table?
body: <p>I have two tables, they have a same column <code>id</code>, but <code>table1</code> has more <code>id</code>s than <code>table2</code>. Now I want to find those <code>id</code>a in <code>table1</code> but not exist in <code>table2</code>, and <code>insert</code> them into <code>table2</code>, and set their value of count as 0.</p>
  
  <p>I tried the following code but it says <code>syntax error, unexpected IF</code>.</p>
  
  <pre><code>if not exists(select * from table1 where table1.id = table2.id)
  begin
      insert into table2 (id, count) values (table1.id, 0)
  end
  </code></pre>