Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Server 2005 Table with validation rule

Posted on 2010-09-16
5
Medium Priority
?
632 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 1000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

972 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