Niyaz Niyaz - 1 year ago 84
MySQL Question

How do I specify unique constraint for multiple columns in MySQL?

I have a table:

table votes (
primary key(id),

Now I want to make the columns user, email, address unique (together).

How do I do this in MySql?

  • Of course the example is just... an example. So please don't worry about the semantics.

Answer Source
ALTER TABLE `votes` ADD UNIQUE `unique_index`(`user`, `email`, `address`);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download