Hello readers, Here are going to create a Check Constraint in SQL Server to allow only Alphabets in Column.

Check Constraint in SQL Server to  in the column:

Sometimes you face a situation to allow alphabets in columns. This is the real-world scenario.  Here I am going to create a Check Constraint that will prevent any character other than Alphabets.


Create Table:

CREATE TABLE EmployeeDetails
(ID INT, EmployeeName VARCHAR(100),
CONSTRAINT chkEmployeeName CHECK (EmployeeName NOT LIKE '%[^A-Z]%'))

In the above script, i have created a Check Constraint called chkEmployeeName that will check if EmployeeName is not an Alphabet.

Test Check Constraint:

INSERT INTO [dbo].[EmployeeDetails] (ID, EmployeeName)
VALUES (1, 'DebugOnWeb')

If you run the above run the above query it will run without any error, Now run the following query.

INSERT INTO [dbo].[EmployeeDetails] (ID, EmployeeName)
VALUES (1, 'DebugOnWeb 1')

If you run the above following error will be raised.

Allow only Alphabets

So this simple Constraint solve the problem of allowing Alphabets in column

View More:


I hope this Check Constrain of allowing only Alphabets in the column will solve your real-world problems. I would like to have your feedback, comments, and suggestions.

Thank You.

Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, bool given in C:\inetpub\vhosts\debugonweb.com\httpdocs\wp-includes\wp-db.php on line 3353