John_2357
asked on
In MySQL column, how do I only allow data that matches a certain pattern?
I am using a current version of MySQL
I have created a table:
CREATE TABLE IF NOT EXISTS `Uniq_Entity` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`ein` VARCHAR (50) NULL ,
UNIQUE KEY `uq_ein` (ein)
)
ENGINE = InnoDB;
I just was asked to prevent the ein field from having any value other than this pattern:
[0-9a-zA-Z]{18}[0-9]{2}
We are importing the data from a csv file using LOAD DATA LOCAL INFILE .
How do I modify the CREATE TABLE so any attempt to INSERT or UPDATE ein with data that does not match this pattern gets rejected?
Alternatively, how would I modify the INSERT or UPDATE query that would ignore any field that fails to match?
Thanks in advance!
I have created a table:
CREATE TABLE IF NOT EXISTS `Uniq_Entity` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`ein` VARCHAR (50) NULL ,
UNIQUE KEY `uq_ein` (ein)
)
ENGINE = InnoDB;
I just was asked to prevent the ein field from having any value other than this pattern:
[0-9a-zA-Z]{18}[0-9]{2}
We are importing the data from a csv file using LOAD DATA LOCAL INFILE .
How do I modify the CREATE TABLE so any attempt to INSERT or UPDATE ein with data that does not match this pattern gets rejected?
Alternatively, how would I modify the INSERT or UPDATE query that would ignore any field that fails to match?
Thanks in advance!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER