Dropping Unique constraint from MySQL table

Mysql

Mysql Problem Overview


How can I drop the "Unique Key Constraint" on a column of a MySQL table using phpMyAdmin?

Mysql Solutions


Solution 1 - Mysql

A unique constraint is also an index.

First use SHOW INDEX FROM tbl_name to find out the name of the index. The name of the index is stored in the column called key_name in the results of that query.

Then you can use DROP INDEX:

DROP INDEX index_name ON tbl_name

or the ALTER TABLE syntax:

ALTER TABLE tbl_name DROP INDEX index_name

Solution 2 - Mysql

You can DROP a unique constraint from a table using phpMyAdmin as requested as shown in the table below. A unique constraint has been placed on the Wingspan field. The name of the constraint is the same as the field name, in this instance.

alt text

Solution 3 - Mysql

The indexes capable of placing a unique key constraint on a table are PRIMARY and UNIQUE indexes.

To remove the unique key constraint on a column but keep the index, you could remove and recreate the index with type INDEX.

Note that it is a good idea for all tables to have an index marked PRIMARY.

Solution 4 - Mysql

To add UNIQUE constraint using phpmyadmin, go to the structure of that table and find below and click that,

enter image description here

To remove the UNIQUE constraint, same way, go to the structure and scroll down till Indexes Tab and find below and click drop, enter image description here

Hope this works.

Enjoy ;)

Solution 5 - Mysql

If you want to remove unique constraints from MySQL database table, use alter table with drop index.

Example:

CREATE TABLE unique_constraints (
    unid INT,
    activity_name VARCHAR(100),
    CONSTRAINT activty_uqniue UNIQUE (activity_name),
    PRIMARY KEY (unid)
);
ALTER TABLE unique_constraints
DROP INDEX activty_uqniue;

Where activty_uqniue is UNIQUE constraint for activity_name column.

Solution 6 - Mysql

For WAMP 3.0 : Click Structure Below Add 1 Column you will see '- Indexes' Click -Indexes and drop whichever index you want.

Solution 7 - Mysql

The constraint could be removed with syntax:

> ALTER TABLE > >As of MySQL 8.0.19, ALTER TABLE permits more general (and SQL standard) syntax for dropping and altering existing constraints of any type, where the constraint type is determined from the constraint name: ALTER TABLE tbl_name DROP CONSTRAINT symbol;

Example:

CREATE TABLE tab(id INT, CONSTRAINT unq_tab_id UNIQUE(id));

-- checking constraint name if autogenerated
SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME = 'tab';

-- dropping constraint
ALTER TABLE tab DROP CONSTRAINT unq_tab_id;

db<>fiddle demo

Solution 8 - Mysql

This might help:

Inside your sql terminal

FIRST STEP:

> SHOW INDEX FROM {YOUR_TABLE_NAME}

SECOND STEP:

> SHOW INDEX FROM {YOUR_TABLE_NAME} WHERE Column_name='ACTUAL_COLUMN_NAME_YOU_GOT_FROM_FIRST_STEP_OUTPUT'

THIRD STEP:

> ORIGINAL_KEY_NAME_VALUE = SECOND_STEP_RESPONSE["Key_name"]

FOURTH STEP:

> ALTER TABLE {YOUR_TABLE_NAME} DROP INDEX ${ORIGINAL_KEY_NAME_VALUE}

Solution 9 - Mysql

while dropping unique key we use index

ALTER TABLE tbl
DROP INDEX  unique_address;

Solution 10 - Mysql

my table name is buyers which has a unique constraint column emp_id now iam going to drop the emp_id

step 1: exec sp_helpindex buyers, see the image file

step 2: copy the index address

enter image description here

step3: alter table buyers drop constraint [UQ__buyers__1299A860D9793F2E] alter table buyers drop column emp_id

note:

> Blockquote

instead of buyers change it to your table name :)

> Blockquote

thats all column name emp_id with constraints is dropped!

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
QuestionAnkur MukherjeeView Question on Stackoverflow
Solution 1 - MysqlMark ByersView Answer on Stackoverflow
Solution 2 - MysqlGeoffreyView Answer on Stackoverflow
Solution 3 - MysqlthomasrutterView Answer on Stackoverflow
Solution 4 - MysqlUmesh PatilView Answer on Stackoverflow
Solution 5 - MysqlManjunatha H CView Answer on Stackoverflow
Solution 6 - MysqlJeffry LouisView Answer on Stackoverflow
Solution 7 - MysqlLukasz SzozdaView Answer on Stackoverflow
Solution 8 - MysqlAsad ZamanView Answer on Stackoverflow
Solution 9 - MysqlHamza.SView Answer on Stackoverflow
Solution 10 - Mysqlvignesh .BView Answer on Stackoverflow