Discussion:
Alter combination of 2 existing columns as a unique key
(too old to reply)
James
2007-04-19 18:07:21 UTC
Permalink
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
Gordon Burditt
2007-04-19 23:48:31 UTC
Permalink
Post by James
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.
Loading...