Allow only alphabets in column in SQL Server
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:
Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course by GeeksforGeeks.
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.
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.