How to alter a MySQL table's foreign key using the command line

前端 未结 4 2055
一整个雨季
一整个雨季 2021-02-13 19:49

How to alter an existing table in MySQL, setting foreign key to another table, using the command line?

4条回答
  •  执念已碎
    2021-02-13 19:53

    You have to drop existing foreign key and create another one. For example like this:

    ALTER TABLE my_table DROP FOREIGN KEY my_key;
    ALTER TABLE my_table ADD CONSTRAINT my_key FOREIGN KEY ('some_id') 
    REFERENCES some_new_table ('some_other_id') ON UPDATE CASCADE ON DELETE CASCADE;
    

提交回复
热议问题