How to use CHECK constraint to restrict non-numeric varchar2 (only alphabets)?

StackOverflow https://stackoverflow.com/questions/8756659

  •  14-04-2021
  •  | 
  •  

Вопрос

I have a column NAME
It must contain only characters and not numbers
How do I use CHECK condition:

CHECK(NAME NOT LIKE '%[0-9]%')

or any other method...

edit: Oracle database is used.

Это было полезно?

Решение

You didn't state your DBMS so I'm assuming PostgreSQL

CHECK(name ~ '^[^0-9]*$')

Другие советы

Double negative Should be standard (not MySQL though) because it uses LIKE:

CHECK(NAME NOT LIKE '%[^a-zA-Z]%')
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top