🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to MySQL Notes
Topic #57

MySQL Check


MySQL CHECK Constraint

The CHECK constraint is used to ensure that the values in a column satisfies a specific condition.

The CHECK constraint evaluates the data to TRUE or FALSE. If the data evaluates to TRUE, the operation is ok. If the data evaluates to FALSE, the entire INSERT or UPDATE operation is aborted, and an error is raised.


CHECK Constraint on CREATE TABLE

The following SQL creates a CHECK constraint on the "Age" column upon creation of the "Persons" table.

Here, the CHECK constraint ensures that the "Age" column must have a value of 18, or above:

CREATE TABLE Persons
(
    ID int PRIMARY KEY,

LastName varchar(255) NOT NULL,

FirstName varchar(255),

Age int CHECK (Age >= 18)
);

Naming a CHECK Constraint

To name a CHECK constraint, or to define a CHECK constraint on multiple columns, use the following SQL syntax:

CREATE TABLE Persons
(
    ID int PRIMARY KEY,

LastName varchar(255) NOT NULL,

FirstName varchar(255),

Age int,

City varchar(255),

CONSTRAINT chk_PersonAge CHECK (Age >= 18 AND City = 'Sandnes')
);

CHECK Constraint on ALTER TABLE

To create a CHECK constraint on the "Age" column when the table is already created, use the following SQL:

ALTER TABLE Persons
ADD CHECK (Age >= 18);

Naming a CHECK Constraint

To name a CHECK constraint, and to define a CHECK constraint on multiple columns, use the following SQL syntax:

ALTER TABLE Persons
ADD CONSTRAINT chk_PersonAge CHECK (Age >= 18 AND City = 'Sandnes');

Drop a CHECK Constraint

To drop a CHECK constraint, use the following SQL:

ALTER TABLE Persons
DROP CHECK chk_PersonAge;

Want to go beyond the notes?

Join CodingNow 2.0's MySQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

MySQL Check – FAQs

Quick answers about learning MySQL Check in MySQL.

This free note from CodingNow 2.0 explains MySQL Check in MySQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every MySQL topic on CodingNow 2.0, including MySQL Check, is 100% free with no signup required.
With focused practice, most students grasp MySQL Check in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now