- It is used for applying Business rules on a paticular column.
Like sal>2000, deptno is not null, lenght of username > 5, length of password >= 8 etc...
- It allows NULL values.
Syntax:
column_name datatype [size] CONSTRAINT <constraint_name> CHECK <condition>;
Examples:
(i) Creating a Check Constraint.
Column Level Check declaration.
create table emp
(empno number(4), ..., sal number(7,2) CONSTRAINT check_sal check (sal > 3000),............);
Table level Check Constraint.
create table emp
(empno number(4), ...... sal number(7,2), .......,
CONSTRAINT check_sal check (sal > 3000),...............);
Using Alter
create table emp
(empno number(4), ...... sal number(7,2), .......)
Alter table emp add ( CONSTRAINT check_sal check (sal > 3000) );
(ii) Drop Check constraint.
Alter table emp drop CONSTRAINT check_sal;
Like sal>2000, deptno is not null, lenght of username > 5, length of password >= 8 etc...
- It allows NULL values.
Syntax:
column_name datatype [size] CONSTRAINT <constraint_name> CHECK <condition>;
Examples:
(i) Creating a Check Constraint.
Column Level Check declaration.
create table emp
(empno number(4), ..., sal number(7,2) CONSTRAINT check_sal check (sal > 3000),............);
Table level Check Constraint.
create table emp
(empno number(4), ...... sal number(7,2), .......,
CONSTRAINT check_sal check (sal > 3000),...............);
Using Alter
create table emp
(empno number(4), ...... sal number(7,2), .......)
Alter table emp add ( CONSTRAINT check_sal check (sal > 3000) );
(ii) Drop Check constraint.
Alter table emp drop CONSTRAINT check_sal;
No comments:
Post a Comment