Home > database >  How to check in MySQL if a string is solely made up of the letters of the English alphabet?
How to check in MySQL if a string is solely made up of the letters of the English alphabet?

Time:10-24

Consider the following minimal example.

CREATE TABLE Student (
  Name varchar(50),
  CHECK (isEnglish(Name))
)

I want to add a constraint that the name is in the English alphabet (a-z, A-Z) while inserting a new tuple in the STUDENT table. How do I do this? That is, what should I put in place of isEnglish(Name)?

CodePudding user response:

Hope this helps but works on MySQL 8.0

CREATE TABLE Student (
  Name varchar(50) CHECK (Name REGEXP '^[A-Za-z] $')
)
  • Related