Solved

SQL Server 2005 Table with validation rule

Posted on 2010-09-16
5
628 Views
Last Modified: 2012-06-21
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
Comment
Question by:HNA071252
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 9

Expert Comment

by:jerrypd
ID: 33694493
I would use an insert trigger to validate the data, then return a failure code if it is outside of your "acceptable" parameters.
0
 

Author Comment

by:HNA071252
ID: 33694537
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
 
LVL 9

Expert Comment

by:jerrypd
ID: 33694594
SQL and access are two completely different beasts. Let me see if I can get something for you...
0
 
LVL 9

Accepted Solution

by:
jerrypd earned 250 total points
ID: 33694699
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
 

Author Closing Comment

by:HNA071252
ID: 33697438
Thanks.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question