Dropping Unique constraint from MySQL table

后端 未结 10 886
孤城傲影
孤城傲影 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: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

提交回复
热议问题