?
Solved

column can only enter letters of the alphabet

Posted on 2010-08-13
5
Medium Priority
?
514 Views
Last Modified: 2012-08-13
Hi experts,
as I can validate that a column can only enter letters of the alphabet
0
Comment
Question by:enrique_aeo
  • 3
5 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 33434496
You need to add a CONTRAINT on that column something like this:
ALTER TABLE dbo.YourTableName ADD CONSTRAINT AlphaOnly CHECK (PATINDEX('%[^A-Z]%', YourColumnName) > 0)
0
 

Author Comment

by:enrique_aeo
ID: 33434542
HI
create table datosPersonales (nombre varchar(100))
go
ALTER TABLE datosPersonales
      ADD CONSTRAINT nombre CHECK (PATINDEX('%[^A-Z]%', nombre) > 0)
      
insert into datosPersonales values ('ABCD')
i have this error
Msg 547, Level 16, State 0, Line 1
The INSERT statement conflicted with the CHECK constraint "nombre". The conflict occurred in database "AdventureWorks", table "dbo.datosPersonales", column 'nombre'.
The statement has been terminated.

0
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 200 total points
ID: 33434554
Use WITH NOCHECK
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 800 total points
ID: 33434660
It means you already have data that conflicts with your own rules.  If you do not care about existing data than use WITH NOCHECK.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 800 total points
ID: 33434704
Oops I am sorry it looks like I mislead you the check constraint should have read:
ALTER TABLE dbo.YourTableName ADD CONSTRAINT AlphaOnly CHECK (PATINDEX('%[^A-Z]%', YourColumnName) = 0)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

831 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