Friday, June 22, 2018

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



I have a table:



table votes (
id,
user,
email,

address,
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



ALTER TABLE `votes` ADD UNIQUE `unique_index`(`user`, `email`, `address`);

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...