ORA-25158: Cannot specify RELY for foreign key if the associated primary key is NORELY ORACLE 报错 故障修复 远程处理

文档解释

ORA-25158: Cannot specify RELY for foreign key if the associated primary key is NORELY

Cause: RELY is specified for the foreign key contraint, when the associated primary key constraint is NORELY.

Action: Change the option of the primary key also to RELY.

ORA-25158 错误指示不能为具有NORELY主键的外键指定RELY选项。

官方解释

如果创建外键时主键属性为NORELY,则不能为外键设置RELY属性。所以要么让外键使用NORELY属性,要么让主键使用RELY属性。

常见案例

当您使用以下语句创建外键时,将会出现这个错误:

ALTER TABLE child

ADD CONSTRAINT child_fk

FOREIGN KEY (parent_id)

REFERENCES parent (id);

一般处理方法及步骤

要解决这个错误,您可以为主键添加RELY属性:

ALTER TABLE parent

MODIFY id NOT NULL RELY;

或者您可以为外键添加NORELY属性:

ALTER TABLE child

ADD CONSTRAINT child_fk

FOREIGN KEY (parent_id)

REFERENCES parent (id)

NO RELY;


数据运维技术 » ORA-25158: Cannot specify RELY for foreign key if the associated primary key is NORELY ORACLE 报错 故障修复 远程处理