Open In App

Allow only alphabets in column in SQL Server

Improve
Improve
Like Article
Like
Save
Share
Report

There may occur some situations when data in column should only be in alphabets, for example: Name column in details table. If user try to input other than alphabets, it will give error. To allow only alphabets in a column check constraint can be applied over column. 
To get information about Constraints and Check Constraints, refer below article links: 
 

Syntax: 
 

CONSTRAINT (Constraint_Name) 
CHECK ( BOOLEAN EXPRESSION)

Example 1: In this example, constraints are applied on ADDRESS column to check if value inserted in ADDRESS column consist of only alphabets or not. The value inserted in ADDRESS column consists of only alphabets and thus it works fine and does not show any error. The condition NOT LIKE %[^A-Z]% checks is input values are alphabets or not. 
 

Output: 
 

Example 2: In this example, constraints are applied on ADDRESS column to check if entered value consist of only alphabets or not. The value inserted in ADDRESS column consists of alphabets and integer and thus it shows error. The ADDRESS “GEEKS1” is responsible for error. 
 

Output: 
 

 


Last Updated : 30 Aug, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads