Alter combination of 2 existing columns as a unique key

To alter 1 column to a unique key,

ALTER TABLE user MODIFY COLUMN id INT NOT NULL UNIQUE;

But how to set combination of 2 columns as a unique key?
Individual keys are not unique, but combination is.

TIA,
James
James [ Do, 19 April 2007 20:07 ] [ ID #1692175 ]

Re: Alter combination of 2 existing columns as a unique key

>To alter 1 column to a unique key,
>
>ALTER TABLE user MODIFY COLUMN id INT NOT NULL UNIQUE;
>
>But how to set combination of 2 columns as a unique key?
>Individual keys are not unique, but combination is.

ALTER TABLE user ADD UNIQUE (id,domain);

That just adds an index. You might need to drop an old one first. Or not.
gordonb.4k7va [ Fr, 20 April 2007 01:48 ] [ ID #1693372 ]
Datenbanken » mailing.database.mysql » Alter combination of 2 existing columns as a unique key

Vorheriges Thema: percentage in sql query
Nächstes Thema: backing up mysql