Pages

Men

rh

10/30/2013

Check Constraints in SQL Server

A Check Constraints restricts the data values that users can enter into a particular column during INSERT  and UPDATE statements.

We can apply Check Constraints at the column level or table level.

A Column Level Check Constraints  restrict the values that  can be stored in that column.

A Table Level Check Constraints can refer multiple columns in the same table to allow for cross referencing and comparison of column values.

Consider the following facts before you implement a CHECK Constraints.

  • A CHECK Constraints verify data every time executes an INSERT or UPDATE statements.
  • CHECK Constraints can be any logical expression that returns true or false.
  • CHECK Constraints can not contain Sub Queries.
  • A single column can have multiple CHECK Constraints.
  • CHECK Constraints can not be placed on column with the rowversion data type.
  • The data base Consistency Checker(DBCC) CHECK Constraints statements will return any rows containg data that violates a CHECK Constraint.


When to use CHECK Constraints
  • Business logic dictates that the data stored in  a column must be a member of a specific set or range of values.
  • The data stored in a column has natural limits on the values it can contain.
  • Relationship exist between the columns of a table that restrict the values a column can contain.

No comments :

Post a Comment