Blog

ORA-02438: Column check constraint cannot reference other columns

Cause: attempted to define a column check constraint that references another column.

Action: define it as a table check constraint.

Scenario 1: When you really are referring to other column in Create statement

SQL> create table test_table
  2  (
  3    id      number(10),
  4    name    varchar2(200)  check (age >= 0),
  5    age     number(3)
  6  );
  name    varchar2(200)  check (age >= 0),
                                         *
ERROR at line 4:
ORA-02438: Column check constraint cannot reference other columns

Solution: Just Correct the statement

SQL> create table test_table
  2  (
  3    id      number(10),
  4    name    varchar2(200),
  5    age     number(3) check (age >= 0)
  6  );

Table created.

Scenario 2: When you do a silly spelling mistake in Alter table statement

SQL> create table test_table
  2  (
  3    id      number(10),
  4    name    varchar2(200),
  5    age     number(3)
  6  );

Table created.

SQL> alter table test_table add contraint test_check check (age >=0);
alter table test_table add contraint test_check check (age >=0)
                                                              *
ERROR at line 1:
ORA-02438: Column check constraint cannot reference other columns

Solution: Just Correct the spelling 🙂

SQL> alter table test_table add constraint test_check check (age >=0);

Table altered.

Follow me

Contact us for Training/ Job Support

Caution: Your use of any information or materials on this website is entirely at your own risk. It is provided for educational purposes only. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.