title: REPLACE versus INSERT in SQL
body: <p>I am doing the following SQL tutorial: <a href="http://sql.learncodethehardway.org/book/ex11.html" rel="noreferrer">http://sql.learncodethehardway.org/book/ex11.html</a></p>
  
  <p>and in this exercise the author says in the second paragraph:</p>
  
  <blockquote>
    <p>In this situation, I want to replace my record with another guy but
    keep the unique id. Problem is I'd have to either do a DELETE/INSERT
    in a transaction to make it atomic, or I'd need to do a full UPDATE.</p>
  </blockquote>
  
  <p>Could anyone explain to me what the problem is with doing an UPDATE, and <strong>when</strong> we might choose REPLACE instead of UPDATE?</p>
  
  <p>The UPDATE code:</p>
  
  <pre><code>UPDATE person SET first_name = "Frank", last_name = "Smith", age = 100
      WHERE id = 0;
  </code></pre>
  
  <p>Here is the REPLACE code:</p>
  
  <pre><code>REPLACE INTO person (id, first_name, last_name, age)
      VALUES (0, 'Frank', 'Smith', 100);
  </code></pre>
  
  <p>EDIT: I guess another question I have is why would you ever do a DELETE/INSERT instead of just an UPDATE as is discussed in the quoted section?</p>