Drop foreign key only if it exists

前端 未结 7 2067
清歌不尽
清歌不尽 2021-02-05 01:37

I\'m on a MySQL database.

I\'m doing this, but it doesn\'t work.

ALTER TABLE `object` DROP FOREIGN KEY IF EXISTS `object_ibfk_1`;

I\'ve

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 02:36

    Similar discussion: How do I drop a foreign key constraint only if it exists in sql server?

    IF (OBJECT_ID('FK_ConstraintName', 'F') IS NOT NULL)
    

    is very useful and not mentioned yet here.

提交回复
热议问题