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

后端 未结 14 1997
庸人自扰
庸人自扰 2020-11-21 06:50

I have a table:

table votes (
    id,
    user,
    email,
    address,
    primary key(id),
);

Now I want to make the columns user

14条回答
  •  甜味超标
    2020-11-21 07:25

    I have 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 the UNIQUE KEY works just as expected, it allows multiple NULL rows of id_box_elements and id_router.

    I am running MySQL 5.1.42, so probably there was some update on the issue discussed above. Fortunately it works and hopefully it will stay that way.

提交回复
热议问题