How to Allow Only Alphabets in Column ā€“ Create Check Constraint to Insert Only Alphabets | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

How to Allow Only Alphabets in Column ā€“ Create Check Constraint to Insert Only Alphabets

CREATE TABLE TestTable (ID INT, Name VARCHAR(100), CONSTRAINT NameCHECK (Name NOT LIKE '%[^A-Z]%')) GO -- This will be successful INSERT INTO TestTable (ID, Name) VALUES (1, 'Akwin Lopez') GO -- This will throw an error INSERT INTO TestTable (ID, Name) VALUES (1, 'Akwin Lopez 1') GO

28th Mar 2017, 10:02 AM
Akwin Lopez
Akwin Lopez - avatar
1 Resposta
- 1
You cannot give regular expressions in LIKE statement. You can use :REGEXP_LIKE(Name,'[a-zA-Z] *') in oracle. Similar functions will be available for other databases.
18th May 2017, 5:39 AM
Mohan D
Mohan D - avatar