MySQL Make a combination of columns unique -


i have table stores comments users make images on site. table structured 4 columns, row_id, primary key, image_id, user_id , comment. want ensure user can leave 1 comment per image. create unique index on 2 columns?

create unique index imgusr on comments (image_id, user_id); 

the idea following query work:

insert comments set image_id = '1', user_id = '2', comment = 'nice' on duplicate key update comment = 'nice'; 

the gotchya (gotme?) table innodb because expected large. approach work, despite presence of primary key?

yes work perfectly.

in topic, why did have row_id ? can put primary key (image_id, user_id), works too.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -