Skip to Main Content
  • Questions
  • Trying to create a foreign-key table with on update action, but failed to do so with an error as shown in the question part

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question.

Asked: March 03, 2024 - 9:13 pm UTC

Last updated: March 07, 2024 - 6:30 am UTC

Version: 15

Viewed 1000+ times

You Asked

Hello There,

Thanks for your valuable time & efforts while giving support.

I recently started learning Oracle SQL and PL/SQL for my project purpose. While trying to create a foreign key over in a column in the table with modifier ON UPDATE RESTRICTED, below is the error I am getting

CREATE TABLE supplier_groups(
    group_id NUMBER GENERATED BY DEFAULT AS IDENTITY,
    group_name VARCHAR2(255) NOT NULL,
    constraint grp_id PRIMARY KEY (group_id));

CREATE TABLE suppliers (
    supplier_id NUMBER GENERATED BY DEFAULT AS IDENTITY,
    supplier_name VARCHAR2(255) NOT NULL,
    group_id NUMBER NOT NULL,
    PRIMARY KEY(supplier_id),
    CONSTRAINT fk_grpid 
        FOREIGN KEY(group_id) 
            REFERENCES supplier_groups(group_id) ON UPDATE RESTRICT
);


at UPDATE STATEMENT is shown with pink underlined; stating that: syntax error. partially recognized rules.

would anyone help me understand the mistake /error.

Thank you again.

and Chris said...

The ON UPDATE clause for foreign keys is unsupported in Oracle Database. While this may work in other databases, it's invalid in Oracle SQL.

ON UPDATE RESTRICT means you can't update the parent value if there's a child row referencing it. This is the behaviour for foreign keys in Oracle Database, so you can remove this clause.

Rating

  (1 rating)

Comments

clarification on use of 'ON UPDATE' clause in foreign key constraint

tech champs, March 06, 2024 - 5:20 pm UTC

Many Thanks for clearing my doubt, Chris.

Want to bring to the you (& the forum) notice when I googled about clauses ON UPDATE, ON DELETE usage in Oracle, couple of documents gave example for 'UP UPDATE' clause usage; however, the example didn't work in-reality. This is where I had to do further investigation, then posted my question here in the oracle-forum. However, I searched through the Oracle 19c and 23c SQL Reference document, in which there is no information related to 'ON UPDATE' clause usage; this findings further added value to your comments.

What bothers me, if there is any oracle official document /portal that is similar to as explained in the links I attached below, and you recommend to me to optimize my learning process:

https://docs.oracle.com/cd/B10500_01/appdev.920/a96590/adg05itg.htm

https://docs.oracle.com/cd/B10500_01/server.920/a96524/c22integ.htm


https://docs.oracle.com/javadb/10.8.3.0/ref/rrefsqlj13590.html#rrefsqlj13590 (the link that got example with 'ON UPDATE' clause)
Connor McDonald
March 07, 2024 - 6:30 am UTC

I don't find references to "ON UPDATE" in the first two links, and the third one isn't a reference for the Oracle Database but for the Derby database.