miguel__frtt
miguel__frtt

Reputation: 73

Check if a varchar column only has alphabetical chars

I want to have a check constraint that only allows inserts of alphabetic chars like: 'A' 'Marie', not allowing something like '1' '*#€*a'.

At the moment o have this expression:

CONSTRAINT CK_Pn CHECK (Name LIKE '%[^A-Za-z]%'

Upvotes: 0

Views: 277

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270723

You can use not like:

CONSTRAINT CK_Pn CHECK (Name NOT LIKE '%[^A-Za-z]%'))

That is, Name has no characters that are not alphabetic characters.

Upvotes: 1

Related Questions