在 Oracle 中更改 FK 删除规则而不删除和重新创建它?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4375189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:07:38  来源:igfitidea点击:

Changing a FK delete rule in Oracle without dropping and recreating it?

oracleforeign-keys

提问by Greg

Is there a way to change a table FK delete rule in Oracle better than dropping and then adding it again?

有没有比删除然后再次添加更好的方法来更改 Oracle 中的表 FK 删除规则?

I'm currently using:

我目前正在使用:

alter table A
drop constraint my_fk;

alter table A
add constraint my_fk
foreign key (id)
references B(id)
ON DELETE SET NULL;

As you can see, I already have a FK constraint but it had no delete rule on it. I just want to add an ON DELETE SET NULL rule, and that's what I came up with so far, but I'm feeling it should be simpler.

如您所见,我已经有一个 FK 约束,但它没有删除规则。我只想添加一个 ON DELETE SET NULL 规则,这就是我目前想到的,但我觉得它应该更简单。

采纳答案by Michael Pakhantsov

No other way, except drop and re-create constraint. Oracle have syntax ALTER TABLE x MODIFY CONSTRAINT, but it can be used only for change state of constraint.

除了删除并重新创建约束之外别无他法。Oracle 有语法 ALTER TABLE x MODIFY CONSTRAINT,但它只能用于更改约束状态。

http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_3001.htm

http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_3001.htm