如何在 Oracle 上使用“ON UPDATE CASCADE”创建外键?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1289877/
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-10 02:05:56  来源:igfitidea点击:

How to create a Foreign Key with "ON UPDATE CASCADE" on Oracle?

oracleforeign-keysddl

提问by Daniel Silveira

In MS SQL Server it is possible to create a foreign key with ON UPDATE CASCADEoption, so whenever you update one of the columns in the primary key, the foreign keys in other tables will also be update by the DBMS.

在 MS SQL Server 中,可以使用ON UPDATE CASCADE选项创建外键,因此无论何时更新主键中的列之一,其他表中的外键也将由 DBMS 更新。

So, how to do it in Oracle?

那么,如何在Oracle中做到这一点呢?

回答by Yves

Oracle does not allow a Foreign Key constraint with “ON UPDATE CASCADE”.

Oracle 不允许带有“ON UPDATE CASCADE”的外键约束。

Here are a couple of options you have.

这里有几个选项可供您选择。

Create the Foreign Key, and create an “On Update” trigger. Make use of the package below (needs to be installed in the db).

创建外键,并创建“更新时”触发器。使用下面的包(需要安装在数据库中)。

http://tkyte.blogspot.com/2009/10/httpasktomoraclecomtkyteupdatecascade.html

http://tkyte.blogspot.com/2009/10/httpasktomoraclecomtkyteupdatecascade.html

Let me know if you have additional questions or need more information.

如果您有其他问题或需要更多信息,请告诉我。

回答by berlebutch

Would a database triggerdo the job for you ?

数据库触发器会为您完成这项工作吗?

Here is the Oracle docon the subject of Data Integrity for 11g (just incase you were interested).

这是有关 11g 数据完整性主题的Oracle 文档(以防万一您感兴趣)。