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.
- Mean and Mode in SQL Server
- SQL Server Identity
- SQL SERVER | IN Condition
- SQL Server | SERVERPROPERTY()
- SQL SERVER | Conditional Statements
- SQL Server | STUFF() Function
- Difference between MySQL and MS SQL Server
- Comparisons between Oracle vs SQL Server
- SQL Server Mathematical functions (SQRT, PI, SQUARE, ROUND, CEILING & FLOOR)
- Query to find 2nd largest value in a column in Table
- Count the number of a special day between two dates by using PL/SQL
- MySQLi Procedural Functions
- MySQL | CONNECTION_ID( ) Function
- MySQL | CAST( ) Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.