Tuesday, September 22, 2009

SQL CHECK Constraint in SQL Server 2005

Check Constraint is used for check the value before inserting in to the table.
It is called validation process in software industry.

Below is Syntax for Check Constraint:

ALTER TABLE [TableName]
WITH
CHECK ADD CONSTRAINT [ConstraintName] CHECK
((Condition))

Example:

ALTER TABLE [dbo].[Employee]
WITH
CHECK ADD CONSTRAINT [CK_Employee] CHECK
(([EmployeeId]<>''))

This example is used for Employee table .This Constraint not allowed the '' value in to the Table.


No comments:

Post a Comment