List:General Discussion« Previous MessageNext Message »
From:SGreen Date:July 20 2005 6:00pm
Subject:Re: Remove Unique Key
View as plain text  
Eric Jensen <eric@stripped> wrote on 07/20/2005 02:00:26 PM:

> I have a field that was set as a unique key when created via:
> UNIQUE KEY `username` (`username`)
> 
> I no longer want it unique, but can't see a way with ALTER TABLE to
> remove it.  It isn't the Primary Key or an index.  The describe looks
> like this:
> 
> +----------+-------------+------+-----+---------+-------+
> | Field    | Type        | Null | Key | Default | Extra |
> +----------+-------------+------+-----+---------+-------+
> | username | varchar(25) |      | UNI |         |       |
> +----------+-------------+------+-----+---------+-------+
> 
> Anything I can do short of dumping the table, droping it, then
> re-inserting everything?
> 
> Eric
> 
> 

You have two options:

DROP INDEX (http://dev.mysql.com/doc/mysql/en/drop-index.html)
or
ALTER TABLE DROP INDEX (
http://dev.mysql.com/doc/mysql/en/alter-table.html)

In both commands you will need to provide the name of the key. You can get 
the name of the index from the SHOW CREATE TABLE xxx\G output (where xxx 
is the name of your table). With MySQL, "KEY" is a synonym for "INDEX".

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine



Thread
Remove Unique KeyEric Jensen20 Jul
  • Re: Remove Unique KeyJoseph20 Jul
  • Re: Remove Unique KeySGreen20 Jul