mysql - Check uniqueness for multiple attributes in SQL -


i having table of form id, mid,pid. now, table id primary key. , might come across inserting same combination of mid,pid , shouldn't add them. here id needs generated , can't obtained or crawled. there mechanism in sql check uniqueness of combination.

i thinking of generating id auto increment, being primary key can't here,another option thinking is, concatenate mid , pid , set them primary key. else check if data exists select command , same. these kind of defeats purpose, or least not elegant. there other methods?

will creating constraint serve it?

yes, adding (composite) uniqueness constraint want:

alter table my_table add unique (mid, pid) 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -