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:
CONSTRAINT (Constraint_Name) CHECK ( BOOLEAN EXPRESSION)
Example 1: In this example, contraints 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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.