java2db

Sql CHECK constraint on table column



Business rule validations can be applied on a column using CHECK constraint. It  must be specified by logical or boolean expressions , that each row in the table must satisfy.

 

Sql CHECK constraint Restrictions on a CHECK constraint:

Sql CHECK constraint  Cannot specify it to a view.
Sql CHECK constraint  The condition of a CHECK constraint can refer to any column in the table , but it cannot refer to columns of other tables.
Sql CHECK constraint  CHECK constraint conditions cannot contain the following constructs:
1. Sub queries.
2. Calls to the functions SYSDATE,UID,USER, or USERENV.
3. The pseudocolumns CURRVAL,NEXTVAL,LEVEL, or ROWNUM.
4. Date constants that are not fully specified.

In case of multiple CHECK constraints for a column , design them carefully so their purposes do not conflict and do not assume any particular order of evaluation of the conditions.

 

Sql CHECK constraintCHECK constraint at column level :

Declare the constraint at the end of the column declaration.

 

Sql CHECK constraint CHECK constraint at table level :

Declare the constraint at the end of the last column separated by a “,” . Specify the Check constraint with desired columns with check conditions.

 

Sql CHECK constraintCHECK constraint with ALTER :

We can declare a constraint using alter command , if the table already exists.

 

Sql CHECK constraintDrop CHECK constraint :

Drop the constraint with it’s name.




Related Posts :
Sql FOREIGN KEY constraint on table column
Sql NOT NULL constraint on table column
Sql UNIQUE constraint on table column
Sql PRIMARY KEY constraint on table column
Sql full outer join on tables with an example
Sql right outer join on tables with an example
Sql left outer join on tables with an example
Sql inner join on tables with an example
   [will not be published]



^ <