Monday, 21 August 2017

Check Constraints in Oracle


Check:

  • Check is a domain integrity
  • It should satisfy some condition defined by a user.
  • Modify option is not done in the check constraints.

Syntax :

create table course456( CId Number, CName varchar(20), gender char(1) Not null, constraints c3 check(gender in ('m','f')));

Table Created;

insert into course456 values(1,'parthi','m');
insert into course456 values(2,'arthi','f');

Two Rows inserted

insert into course456 values(2,'arthi','fq');

Error: ORA-12899: value too large for column "HR"."COURSE456"."GENDER" (actual: 2, maximum: 1) 
Note : On creating the table char size defined as 1 but in the table declared value as 2.

insert into course456 values(2,'arthi','h');

Error: ORA-02290: check constraint (HR.C3) violated

Note : The check constraints check some conditions set by the user.Here user set the condition gender as m or f. 

No comments:

Post a Comment