Home » SQL & PL/SQL » SQL & PL/SQL » check constraint (oracle 10g)
check constraint [message #593143] Wed, 14 August 2013 09:44 Go to next message
satheeshsharma
Messages: 11
Registered: August 2013
Location: Chennai
Junior Member

Create table students
(
  Sid  number(3),
  Sname varchar(20)  not null,
  Email varchar(20)  not null,
  Doj  Timestamp    default    sysdate    not null,
  Dob  date     not null,
  Phno number(10),
  Address varchar(20),
  Resume LONG,
  Gender char(1) Default  'M',
  Cid  number,
  Constraint Pk_stu_sid  Primary key(sid,cid),
  Constraint Un_stud_email Unique(email),
  Constraint  chk_stud_email Check(email like '%@%.%'),
  Constraint chk_stud_phno Check(length(phno) = 10),
  Constriant chk_stud_gender Check(gender in ('M','F')),
  Constraint Fk_stud_cid foreign key(cid) references
          course(cid))
)



when i run the above code i m getting error like this...I dont understand wat error it is...Because i didnt reference any column in the check constraint...Thn why it says that i m referencing some column..

Error:


SQL> 
SQL> Create table students
  2  (
  3    Sid  number(3),
  4    Sname varchar(20)  not null,
  5    Email varchar(20)  not null,
  6    Doj  Timestamp    default    sysdate    not null,
  7    Dob  date     not null,
  8    Phno number(10),
  9    Address varchar(20),
 10    Resume LONG,
 11    Gender char(1) Default  'M',
 12    Cid  number,
 13    Constraint Pk_stu_sid  Primary key(sid,cid),
 14    Constraint Un_stud_email Unique(email),
 15    Constraint  chk_stud_email Check(email like '%@%.%'),
 16    Constraint chk_stud_phno Check(length(phno) = 10),
 17    Constriant chk_stud_gender Check(gender in ('M','F')),
 18    Constraint Fk_stud_cid foreign key(cid) references
 19            course(cid))
 20  )
 21  /
  Constriant chk_stud_gender Check(gender in ('M','F')),
                                                       *
ERROR at line 17:
ORA-02438: Column check constraint cannot reference other columns
Re: check constraint [message #593144 is a reply to message #593143] Wed, 14 August 2013 09:55 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
satheeshsharma wrote on Wed, 14 August 2013 20:14
 Constriant chk_stud_gender Check(gender in ('M','F')),
                                                       *
ERROR at line 17:
ORA-02438: Column check constraint cannot reference other columns


Look at the spelling "Constriant". It should be constraint.
Re: check constraint [message #593146 is a reply to message #593144] Wed, 14 August 2013 10:05 Go to previous message
satheeshsharma
Messages: 11
Registered: August 2013
Location: Chennai
Junior Member
wat a silly mistake...Thank u Mr.lalit kumar for helping me
Previous Topic: Need Logic for SQL query
Next Topic: utl_file
Goto Forum:
  


Current Time: Sat Aug 30 11:35:30 CDT 2025