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

后端 未结 14 1991
庸人自扰
庸人自扰 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:15

    I do it like this:

    CREATE UNIQUE INDEX index_name ON TableName (Column1, Column2, Column3);
    

    My convention for a unique index_name is TableName_Column1_Column2_Column3_uindex.

提交回复
热议问题