如何在 MySQL 中删除唯一性?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1564924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:15:50  来源:igfitidea点击:

How to drop unique in MySQL?

mysqlindexingsql-drop

提问by Mask

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?

我想删除唯一键email,如何?

回答by Wael Dalloul

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

只需使用以下 SQL 脚本即可删除 MySQL 中的索引:

alter table fuinfo drop index email;

回答by arty

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).

其中 email 是唯一键(索引)的名称。

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.

IDEX 之后的 email 是索引的名称,它不是可选的。您可以使用 KEY 而不是 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.

其中 email 是列名。

回答by gavin

mysql> DROP INDEX email ON fuinfo;

mysql> 在 fuinfo 上删除 INDEX 电子邮件;

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

其中email是唯一键(而不是列名)。您可以通过以下方式找到唯一键的名称

mysql> SHOW CREATE TABLE fuinfo;

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

在这里您可以看到唯一键的名称,例如可以是 email_2。所以...

mysql> DROP INDEX email_2 ON fuinfo;

mysql> DESCRIBE fuinfo;

This should show that the index is removed

这应该表明该索引已被删除

回答by Chandresh

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.

如果您不知道 key_name,请先尝试以下查询,您可以获得 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

如果要从 mysql 表中删除/删除主键,请使用以下查询

ALTER TABLE `products` DROP INDEX `PRIMARY`;

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

代码取自:http: //chandreshrana.blogspot.in/2015/10/how-to-remove-unique-key-from-mysql.html

回答by Lina Gom

DROP INDEX column_nameON table_name

DROP INDEX column_nameON 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

选择数据库并从 sql 选项卡查询。这将删除特定列的索引。它在 PHP MyADMIN 中对我有用

回答by Md Rashedul Hoque Bhuiyan

This may help others

这可能会帮助其他人

alter table fuinfo drop index fuinfo_email_unique

回答by ArunDhwaj IIITH

For MySQL 5.7.11

对于 MySQL 5.7.11

Step-1: First get the Unique Key

步骤 1:首先获取唯一键

Use this query to get it:

使用此查询来获取它:

1.1) SHOW CREATE TABLE User;

1.1) 显示创建表用户;

In the last, it will be like this:

最后,它会是这样的:

.....

.....

.....

.....

UNIQUE KEY UK_8bv559q1gobqoulqpitq0gvr6(phoneNum)

唯一键UK_8bv559q1gobqoulqpitq0gvr6( phoneNum)

.....

.....

....

....

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

第 2 步:通过此查询删除唯一键。

ALTER TABLE User DROP INDEX UK_8bv559q1gobqoulqpitq0gvr6;

更改表用户删除索引 UK_8bv559q1gobqoulqpitq0gvr6;

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

第 3 步:通过此查询检查表信息:

DESC User;

DESC 用户;

This should show that the index is removed

这应该表明该索引已被删除

Thats All.

就这样。

回答by radhason power

ALTER TABLE 0_value_addition_setup  DROP  INDEX   value_code

回答by Radhason

Try it to remove uique of a column:

尝试删除列的 uique:

ALTER TABLE  `0_ms_labdip_details` DROP INDEX column_tcx

Run this code in phpmyadmin and remove unique of column

在 phpmyadmin 中运行此代码并删除唯一的列

回答by Curtis H

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

this will work.

这会起作用。