Dropping Unique constraint from MySQL table

后端 未结 10 835
孤城傲影
孤城傲影 2020-11-28 01:32

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

相关标签:
10条回答
  • 2020-11-28 01:41

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

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

    Hope this works.

    Enjoy ;)

    0 讨论(0)
  • 2020-11-28 01:42

    while dropping unique key we use index

    ALTER TABLE tbl
    DROP INDEX  unique_address;
    
    0 讨论(0)
  • 2020-11-28 01:43

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

    0 讨论(0)
  • 2020-11-28 01:49

    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

    0 讨论(0)
  • 2020-11-28 01:51

    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!

    0 讨论(0)
  • 2020-11-28 01:52

    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.

    0 讨论(0)
提交回复
热议问题