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

后端 未结 14 2036
庸人自扰
庸人自扰 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...

提交回复
热议问题