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

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

    For PostgreSQL... It didn't work for me with index; it gave me an error, so I did this:

    alter table table_name
    add unique(column_name_1,column_name_2);
    

    PostgreSQL gave unique index its own name. I guess you can change the name of index in the options for the table, if it is needed to be changed...

    0 讨论(0)
  • 2020-11-21 07:33

    You can add multiple-column unique indexes via phpMyAdmin. (I tested in version 4.0.4)

    Navigate to the structure page for your target table. Add a unique index to one of the columns. Expand the Indexes list on the bottom of the structure page to see the unique index you just added. Click the edit icon, and in the following dialog you can add additional columns to that unique index.

    0 讨论(0)
提交回复
热议问题