How to remove constraints from my MySQL table?

前端 未结 12 1371
北恋
北恋 2020-11-30 18:03

I want to remove constraints from my table. My query is:

ALTER TABLE `tbl_magazine_issue` 
DROP CONSTRAINT `FK_tbl_magazine_issue_mst_users`
<
相关标签:
12条回答
  • 2020-11-30 18:39

    I had the same problem and I got to solve with this code:

    ALTER TABLE `table_name` DROP FOREIGN KEY `id_name_fk`;
    ALTER TABLE `table_name` DROP INDEX  `id_name_fk`;
    
    0 讨论(0)
  • 2020-11-30 18:45

    There is no such thing as DROP CONSTRAINT in MySQL. In your case you could use DROP FOREIGN KEY instead.

    0 讨论(0)
  • 2020-11-30 18:47

    There is no DROP CONSTRAINT In MySql. This work like magic in mysql 5.7

    ALTER TABLE answer DROP KEY const_name;
    
    0 讨论(0)
  • 2020-11-30 18:47

    this will works on MySQL to drop constraints

    alter table tablename drop primary key;
    
    alter table tablename drop foreign key;
    
    0 讨论(0)
  • 2020-11-30 18:49

    If the constraint is not a foreign key, eg. one added using 'UNIQUE CONSTRAINT (colA, colB)' then it is an index that can be dropped using ALTER TABLE ... DROP INDEX ...

    0 讨论(0)
  • 2020-11-30 18:50

    Also nice, you can temporarily disable all foreign key checks from a mysql database: SET FOREIGN_KEY_CHECKS=0; And to enable it again: SET FOREIGN_KEY_CHECKS=1;

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