I've got a table:

table votes (

    id,

    user,

    email,

    address,

    primary key(id),

)

Now I wish to result in the posts user, email, address unique (together).

How do you do that in MySql?

Thanks ahead of time.

  • Obviously the example is simply... a good example. So do not be worried about the semantics.
alter table votes add unique index(user, email, address)

Multi column unique indexes fail to work in MySQL for those who have a NULL value in row as MySQL goodies NULL like a unique value and a minimum of presently doesn't have logic to operate around it in multi-column indexes. Yes the behaviour is insane, since it limits lots of legitimate programs of multi-column indexes, but it's what it's... By yet, it's a bug that's been placed with "won't fix" around the MySQL bug-track...

Perhaps you have attempted this ?

UNIQUE KEY `thekey` (`user`,`email`,`address`)

I've got a MySQL table:

CREATE TABLE `content_html` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `id_box_elements` int(11) DEFAULT NULL,

  `id_router` int(11) DEFAULT NULL,

  `content` mediumtext COLLATE utf8_czech_ci NOT NULL,

  PRIMARY KEY (`id`),

  UNIQUE KEY `id_box_elements` (`id_box_elements`,`id_router`)

)

and also the UNIQUE KEY works just like recognized, it enables multiple NULL rows of id_box_elements and id_router.

I'm running MySQL 5.1.42, so most likely there is some update around the problem talked about above. Fortunately it really works and hopefully it'll stay this way.