How to drop unique in MySQL?

MysqlIndexingSql Drop

Mysql Problem Overview


Create Table: CREATE TABLE `fuinfo` (
  `fid` int(10) unsigned NOT NULL,
  `name` varchar(40) NOT NULL,
  `email` varchar(128) NOT NULL,
  UNIQUE KEY `email` (`email`),
  UNIQUE KEY `fid` (`fid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8

I want to drop the unique key on email,how?

Mysql Solutions


Solution 1 - Mysql

Simply you can use the following SQL Script to delete the index in MySQL:

alter table fuinfo drop index email;

Solution 2 - Mysql

There is a better way which don't need you to alter the table:

mysql> DROP INDEX email ON fuinfo;

where email is the name of unique key (index).

You can also bring it back like that:

mysql> CREATE UNIQUE INDEX email ON fuinfo(email);

where email after IDEX is the name of the index and it's not optional. You can use KEY instead of INDEX.

Also it's possible to create (remove) multicolumn unique indecies like that:

mysql> CREATE UNIQUE INDEX email_fid ON fuinfo(email, fid);
mysql> DROP INDEX email_fid ON fuinfo;

If you didn't specify the name of multicolumn index you can remove it like that:

mysql> DROP INDEX email ON fuinfo;

where email is the column name.

Solution 3 - Mysql

mysql> DROP INDEX email ON fuinfo;

where email is the unique key (rather than the column name). You find the name of the unique key by

mysql> SHOW CREATE TABLE fuinfo;

here you see the name of the unique key, which could be email_2, for example. So...

mysql> DROP INDEX email_2 ON fuinfo;

mysql> DESCRIBE fuinfo;

This should show that the index is removed

Solution 4 - Mysql

Use below query :

ALTER TABLE `table_name` DROP INDEX key_name;

If you don't know the key_name then first try below query, you can get key_name.

SHOW CREATE TABLE table_name

OR

SHOW INDEX FROM table_name;

If you want to remove/drop primary key from mysql table, Use below query for that

ALTER TABLE `products` DROP INDEX `PRIMARY`;

Code Taken from: http://chandreshrana.blogspot.in/2015/10/how-to-remove-unique-key-from-mysql.html

Solution 5 - Mysql

DROP INDEX column_name ON table_name

Select the database and query form the sql tab.This removes the index of the particular column. It worked for me in PHP MyADMIN

Solution 6 - Mysql

This may help others

alter table fuinfo drop index fuinfo_email_unique

Solution 7 - Mysql

For MySQL 5.7.11

Step-1: First get the Unique Key

Use this query to get it:

1.1) SHOW CREATE TABLE User;

In the last, it will be like this:

.....

.....

UNIQUE KEY UK_8bv559q1gobqoulqpitq0gvr6 (phoneNum)

.....

....

Step-2: Remove the Unique key by this query.

ALTER TABLE User DROP INDEX UK_8bv559q1gobqoulqpitq0gvr6;

Step-3: Check the table info, by this query:

DESC User;

This should show that the index is removed

Thats All.

Solution 8 - Mysql

ALTER TABLE 0_value_addition_setup  DROP  INDEX   value_code

Solution 9 - Mysql

Try it to remove uique of a column:

ALTER TABLE  `0_ms_labdip_details` DROP INDEX column_tcx

Run this code in phpmyadmin and remove unique of column

Solution 10 - Mysql

 ALTER TABLE [table name] DROP KEY [key name];

this will work.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMaskView Question on Stackoverflow
Solution 1 - MysqlWael DalloulView Answer on Stackoverflow
Solution 2 - MysqlartyView Answer on Stackoverflow
Solution 3 - Mysqlgavin stanleyView Answer on Stackoverflow
Solution 4 - MysqlChandreshView Answer on Stackoverflow
Solution 5 - MysqlLina GomView Answer on Stackoverflow
Solution 6 - MysqlMd Rashedul Hoque BhuiyanView Answer on Stackoverflow
Solution 7 - MysqlArunDhwaj IIITHView Answer on Stackoverflow
Solution 8 - MysqlranojanView Answer on Stackoverflow
Solution 9 - MysqlRadhasonView Answer on Stackoverflow
Solution 10 - MysqlCurtis HView Answer on Stackoverflow