I need to remove a unique key from my mysql table. How can remove that using mysql query.
I tried this but it is not working
alter table tbl_quiz_attempt
For those who don't know how to get index_name
which mentioned in Devart's answer, or key_name
which mentioned in Uday Sawant's answer, you can get it like this:
SHOW INDEX FROM table_name;
This will show all indexes for the given table, then you can pick name of the index or unique key that you want to remove.
Unique key is actually an index. http://codeghar.wordpress.com/2008/03/28/drop-unique-constraint-in-mysql/
To add a unique key use :
alter table your_table add UNIQUE(target_column_name);
To remove a unique key use:
alter table your_table drop INDEX target_column_name;
First you need to know the exact name of the INDEX (Unique key in this case) to delete or update it.
INDEX names are usually same as column names. In case of more than one INDEX applied on a column, MySQL automatically suffixes numbering to the column names to create unique INDEX names.
For example if 2 indexes are applied on a column named customer_id
customer_id
itself.customer_id_2
and so on.SHOW INDEX FROM <table_name>
as suggested by @Amr
ALTER TABLE <table_name> DROP INDEX <index_name>;
There are two method two remove index in mysql. First method is GUI. In this method you have to open GUI interface of MYSQL and then go to that database and then go to that particular table in which you want to remove index.
After that click on the structure option, Then you can see table structure and below you can see table indexes. You can remove indexes by clicking on drop option
Second method by
ALTER TABLE student_login_credentials DROP INDEX created_at;
here student_login_credentials is table name and created_at is column name
ALTER TABLE mytable DROP INDEX key_Name;