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_master drop unique key;
Please help me
Thanks
The syntax for dropping a unique constraint in MySQL is: ALTER TABLE table_name DROP INDEX constraint_name; table_name.
We can remove composite PRIMARY KEY constraint from multiple columns of an existing table by using DROP keyword along with ALTER TABLE statement.
Sometimes we want to add a unique key to the column of an existing table; then, this statement is used to add the unique key for that column. Following are the syntax of the ALTER TABLE statement to add a unique key: ALTER TABLE table_name ADD CONSTRAINT constraint_name UNIQUE(column_list);
All keys are named, you should use something like this -
ALTER TABLE tbl_quiz_attempt_master DROP INDEX index_name;
To drop primary key use this one -
ALTER TABLE tbl_quiz_attempt_master DROP INDEX `PRIMARY`;
ALTER TABLE Syntax.
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>;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With