title: Avoid unique violation in atomic transaction
body: <p>Is possible to create atomic transaction in MySQL?</p>
  
  <p>Consider I have table 'category' with these rows:</p>
  
  <pre><code>id|name
  --|---------
  1 |'tablets'
  2 |'phones'
  </code></pre>
  
  <p>And column <code>name</code> is my primary key.</p>
  
  <p>If I try:</p>
  
  <pre><code>START TRANSACTION;
  update "category" set name = 'phones' where id = 1;
  update "category" set name = 'tablets' where id = 2;
  COMMIT;
  </code></pre>
  
  <p>I'm getting:</p>
  
  <pre><code>ERROR:  duplicate key value violates unique constraint 
  "category_name_key"
  DETAIL:  Key (name)=(tablets) already exists.
  </code></pre>
  
  <p>My expectation is that constraint checks should be done only during commit. Is this possible with MySQL?</p>