• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 633
  • Last Modified:

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.
0
HNA071252
Asked:
HNA071252
  • 3
  • 2
1 Solution
 
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
 
jerrypdCommented:
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
 
HNA071252Author Commented:
Thanks.
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now