Solved

column can only enter letters of the alphabet

Posted on 2010-08-13
5
506 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 50 total points
ID: 33434554
Use WITH NOCHECK
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 200 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 200 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Error - Query 6 50
Amazon RDS migrate to SQL Server 3 34
Stored Proc - Rewrite 42 73
Reformat SQL - so SSRS can read the columns 25 33
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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