SOLVED

ORA-02438: Column check constraint cannot reference other columns

Asked by OracleDba••13 views•oracle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
ORA-02438: Column check constraint cannot reference other columns

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
#oracle#error

Solutions(1)

Accepted Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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.
OracleDba•

Post Your Solution