How to change the foreign key referential action? (behavior)

后端 未结 6 600
眼角桃花
眼角桃花 2020-11-27 13:11

I have set up a table that contains a column with a foreign key, set to ON DELETE CASCADE (delete child when parent is deleted)

What would the SQL com

6条回答
  •  星月不相逢
    2020-11-27 13:33

    You can simply use one query to rule them all: ALTER TABLE products DROP FOREIGN KEY oldConstraintName, ADD FOREIGN KEY (product_id, category_id) REFERENCES externalTableName (foreign_key_name, another_one_makes_composite_key) ON DELETE CASCADE ON UPDATE CASCADE

提交回复
热议问题