Solved

SQL Server 2005 Table with validation rule

Posted on 2010-09-16
5
617 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
  • 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now