Solved

SQL Server 2005 Table with validation rule

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server 2012 Lag Function With Group Levels 1 26
SSRS Deployment problem 5 63
sql server query 12 23
SSRS: Why is Visual Studio stripping these properties? 2 17
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

789 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