Mega Code Archive

 
Categories / MSSQL Tutorial / Constraints
 

A check constraint uses an expression to qualify records that are acceptable for any Inserts or Updates

7> 8> CREATE TABLE MyTable( 9>   MyID Int IDENTITY(1, 1) NOT NULL 10>   ,MyDescription nVarChar(50) NOT NULL 11>   , Region nVarChar(10) NOT NULL 12>   , CONSTRAINT PK_ID PRIMARY KEY CLUSTERED (MyID) 13>   , CONSTRAINT CK_Region CHECK (Region 14>                 IN('PNW','SW','MT','CENTRAL','EAST','SOUTH')) 15>   ) 16> GO 1> 2> drop table MyTable; 3> GO 1> 2>