Solved

SQL Server 2005 Table with validation rule

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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…
Viewers will learn how the fundamental information of how to create a table.

770 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