| id | -> primary key, auto_increment
| v1 |
| v2 |
I want to make sure that there are no duplicate (v1, v2) pairs on insert. Is it possible via an SQL statement? Currently I do a select first and if there ‘s no result I continue with the insert.
I was wondering if there ‘s a better solution.
If you don’t mind an error coming back from the request (you can handle it in your code or as noted elsewhere do your inserts with
INSERT IGNOREto totally suppress the error.), you could put a UNIQUE compound index on v1, v2.