1

假设我有一个外键,其动作是:

on delete set default, on update cascade

如果我想更改操作,如何在 alter table 选项中指定?
我试过这个:

change my_table add on delete cascade my_key;

但它给出了一个语法错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'on delete cascade matricola' at line 1

我想更改删除引用的主键时触发的默认操作。

4

1 回答 1

3
ALTER TABLE my_table DROP FOREIGN KEY my_key;
ALTER TABLE my_table ADD CONSTRAINT my_key FOREIGN KEY ('some_id') 
        REFERENCES some_table ('id') ON UPDATE CASCADE ON DELETE CASCADE;

As far as i know you have to drop your key and create new one with new rules.

于 2012-05-11T09:02:38.480 回答