How to remove unique key on particular mysql table field

北城余情 提交于 2020-08-19 10:19:19

问题


I have assigned unique key in two field username and email. I have execute this query.

ALTER TABLE goipmonl_users DROP INDEX username;

DROP INDEX username ON goipmonl_users

It's show an error. So how can I remove unique key from selected field.

#1091 - Can't DROP 'username'; check that column/key exists.

I have username, email columns in my table.


回答1:


Please find the screen shot to delete unique index from table using phpMyAdmin




回答2:


You can make use of the below command to find out the list of indexes of your table. From that, get the name of your unique index.

SHOW INDEX FROM tbl_name

Then use the below one to drop that index

ALTER TABLE tbl_name DROP INDEX unique_constraint_name;



回答3:


ALTER TABLE [table name] DROP INDEX [unique key constraint name];

Please double check your unique key constraint name, use this command to check:

select distinct CONSTRAINT_NAME
from information_schema.TABLE_CONSTRAINTS
where table_name = [tablename] and constraint_type = 'UNIQUE';



回答4:


Well you can simply do something like this:

```
ALTER TABLE goipmonl_users DROP INDEX goipmonl_users_username_unique;
```

That is you prefix the table name with an underscore followed by the table colunm name to which the constraint is on followed again by underscore finally the index/constraint name which is UNIQUE

hope it will helps someone else that might bump into this issue again



来源:https://stackoverflow.com/questions/40126911/how-to-remove-unique-key-on-particular-mysql-table-field

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!