Dropping Unique constraint from MySQL table

Viewed 245529

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

10 Answers

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

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.

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

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}

while dropping unique key we use index

ALTER TABLE tbl
DROP INDEX  unique_address;

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!

Related