SearchSearch   

Alter combination of 2 existing columns as a unique key

 
   Webmaster Forums (Home) -> MySQL RSS
Next:  backing up mysql  
Author Message
James

External


Since: Apr 19, 2007
Posts: 1



(Msg. 1) Posted: Thu Apr 19, 2007 11:07 am
Post subject: Alter combination of 2 existing columns as a unique key
Archived from groups: mailing>database>mysql (more info?)

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
Back to top
Gordon Burditt

External


Since: Apr 19, 2007
Posts: 1



(Msg. 2) Posted: Thu Apr 19, 2007 11:48 pm
Post subject: Re: Alter combination of 2 existing columns as a unique key
Archived from groups: per prev. post (more info?)

>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.
Back to top
Display posts from previous:   
       Webmaster Forums (Home) -> MySQL
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum