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

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

    For adding unique index following are required:

    1) table_name
    2) index_name
    3) columns on which you want to add index

    ALTER TABLE  `tablename` 
    ADD UNIQUE index-name
    (`column1` ,`column2`,`column3`,...,`columnN`);
    

    In your case we can create unique index as follows:

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

提交回复
热议问题