假设我有一个外键,其行为是:
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
我想更改删除引用的主键时触发的默认操作。
答案 0 :(得分: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;
据我所知,您必须放弃密钥并使用新规则创建新密钥。