MySQL Removing Some Foreign keys

前端 未结 11 704
太阳男子
太阳男子 2020-11-28 01:55

I have a table whose primary key is used in several other tables and has several foreign keys to other tables.

CREATE TABLE location (
   locationID INT NOT         


        
11条回答
  •  伪装坚强ぢ
    2020-11-28 02:18

    As everyone said above, you can easily delete a FK. However, I just noticed that it can be necessary to drop the KEY itself at some point. If you have any error message to create another index like the last one, I mean with the same name, it would be useful dropping everything related to that index.

    ALTER TABLE your_table_with_fk
      drop FOREIGN KEY name_of_your_fk_from_show_create_table_command_result,
      drop KEY the_same_name_as_above
    

提交回复
热议问题