SQL Server 2005 Table with validation rule

I have a table in the SQL Server 2005 table, and I want this table to only allow the value of A, B, or C. How would I put in this validation rule to the table.
HNA071252Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
jerrypdConnect With a Mentor Commented:
you can do it with a constraint...
testtable is the table name
ck_testtable is the constraint name
testchars is the field name

ALTER TABLE [dbo].[testtable]  WITH CHECK ADD  CONSTRAINT [CK_testtable] CHECK  (([testchars]='a' or [testchars]='b'))
0
 
jerrypdCommented:
I would use an insert trigger to validate the data, then return a failure code if it is outside of your "acceptable" parameters.
0
 
HNA071252Author Commented:
So there's no way you can enter the parameters just like in Access? I'm pretty new to SQL programming, how do I do "insert trigger"?
0
 
jerrypdCommented:
SQL and access are two completely different beasts. Let me see if I can get something for you...
0
 
HNA071252Author Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.