FOREIGN KEY ON DELETE RESTRICT 错误 - Oracle

FOREIGN KEY ON DELETE RESTRICT Error - Oracle(FOREIGN KEY ON DELETE RESTRICT 错误 - Oracle)
本文介绍了FOREIGN KEY ON DELETE RESTRICT 错误 - Oracle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我一直在尝试在表中添加以下外键,使用 Oracle 中的 RESTRICT 子句,使用以下命令:

Lately I have been trying to add the following foreign key in the table, with the RESTRICT Clause in Oracle with the following command.:

ALTER TABLE 
Employee_SalHead 
ADD CONSTRAINT PAYROLL_SHEAD_FKEY FOREIGN KEY
(
  SalHead_ID 
)
REFERENCES SalHead
(
  SalHead_ID
)
ON DELETE RESTRICT ENABLE;

这给了我以下错误:

从第 11 行开始的错误命令 - ALTER TABLE Employee_SalHead ADD约束 PAYROLL_SHEAD_FKEY 外键 ( SalHead_ID )REFERENCES SalHead ( SalHead_ID ) ON DELETE RESTRICT ENABLE错误报告 - SQL 错误:ORA-00905:缺少关键字00905. 00000 - 缺少关键字"*原因:
*行动:

Error starting at line : 11 in command - ALTER TABLE Employee_SalHead ADD CONSTRAINT PAYROLL_SHEAD_FKEY FOREIGN KEY ( SalHead_ID ) REFERENCES SalHead ( SalHead_ID ) ON DELETE RESTRICT ENABLE Error report - SQL Error: ORA-00905: missing keyword 00905. 00000 - "missing keyword" *Cause:
*Action:

此外,如果我通过 Oracle SQL 开发人员尝试相同的操作,我只会得到选项 Set Null、Cascade 和 No Action Only.

Also if I try the same through Oracle SQL developer, I get only the options Set Null, Cascade and No Action Only.

推荐答案

Oracle只支持ON DELETE SET NULLON DELETE CASCADE.您只需执行以下查询即可满足您的要求.不用提ON DELETE RESTRICT

Oracle only supports ON DELETE SET NULL and ON DELETE CASCADE. You can achieve your requirement by simply doing the below query. No need to mention ON DELETE RESTRICT

ALTER TABLE Employee_SalHead 
      ADD CONSTRAINT PAYROLL_SHEAD_FKEY FOREIGN KEY(SalHead_ID)
      REFERENCES SalHead(SalHead_ID);

ON DELETE NO ACTION 是默认设置.来自文档

无操作(默认)选项指定如果结果数据违反参照完整性约束,则无法更新或删除引用的键值.例如,如果一个主键值被外键中的值引用,那么由于依赖数据,被引用的主键值不能被删除.

The No Action (default) option specifies that referenced key values cannot be updated or deleted if the resulting data would violate a referential integrity constraint. For example, if a primary key value is referenced by a value in the foreign key, then the referenced primary key value cannot be deleted because of the dependent data.

这篇关于FOREIGN KEY ON DELETE RESTRICT 错误 - Oracle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))
Select the latest record for an Id per day - Oracle pl sql(选择每天ID的最新记录-Oracle pl SQL)