Reputation: 73908
I have a table in MS Sql 2008 r2, I would like add a constrain to a column with I can accept only 3 value like
myColum char(2) constrain values (A1, B2, C3)
Upvotes: 0
Views: 2407
Reputation: 1
CREATE TABLE
(
myColumn char(2) NOT NULL check(myColumn= 'A1' or myColumn= 'B2' myColumn= 'C3')
)
Upvotes: 0
Reputation: 176896
Make use of SQL CHECK Constraint
supported by sql server .
CREATE TABLE test
(
myColum char(2) NOT NULL
CONSTRAINT chk_Person CHECK (myColum in ('A1', 'B2', 'C3'))
)
Upvotes: 2
Reputation: 103579
try:
ALTER TABLE YourTable WITH CHECK ADD CONSTRAINT ck_y CHECK (myColum in ('A1','B2','C3'))
GO
Upvotes: 0
Reputation:
Something like this:
myColum char(2) check (myColum in ('A1', 'B2', 'C3'))
SQLFiddle: http://sqlfiddle.com/#!3/8e304
Upvotes: 3