Churchill
Churchill

Reputation: 81

how to give a check constraint to a character coloumn

How can i give a check constraint to a column whose datatype is char(1)

coloumn name--->group
datatype------->char(1)

CHECK(c,s,a)

plz tell me the exact query how to insert it into sqlserver2005 while creating a table,, in which group is a column...

Thanks, Churchill

Upvotes: 1

Views: 10163

Answers (1)

George Mastros
George Mastros

Reputation: 24506

From your question, it seems as though you only want to allow the value c, s, or a. If I understand correctly....

Create Table YourTableNameHere(
      Id Int, 
      col Char(1) 
      Constraint ConstraintNameHere Check(Col In ('c','s','a')))

Upvotes: 4

Related Questions