title: MySQL Make a combination of columns unique
body: <p>I have a table that stores comments users make about images on the site. The table is structured with four columns, the row_id, which is the primary key, the image_id, the user_id and the comment. What I want to do is ensure that a user can only leave one comment per image. Do I simply create a unique index on the two columns?</p>
  
  <pre><code>CREATE UNIQUE INDEX imgusr ON comments (image_id, user_id);
  </code></pre>
  
  <p>The idea is to get the following query to work:</p>
  
  <pre><code>INSERT INTO comments SET image_id = '1', user_id = '2', comment = 'nice' ON DUPLICATE KEY UPDATE comment = 'nice';
  </code></pre>
  
  <p>The gotchya (gotme?) is that the table is innoDB because it is expected to get very large. Is this the approach that will work, despite the presence of a primary key?</p>