- Introduction To MySQL
 - MySQL RDBMS
 - MySQL SQL
 - MySQL SELECT Statement
 - MySQL WHERE Clause
 - MySQL AND, OR And NOT Operators
 - MySQL ORDER BY Keyword
 - MySQL INSERT INTO Statement
 - MySQL NULL Values
 - MySQL UPDATE Statement
 - MySQL DELETE Statement
 - MySQL LIMIT Clause
 - MySQL MIN() And MAX() Functions
 - MySQL COUNT(), AVG() And SUM() Functions
 - MySQL LIKE Operator
 - MySQL Wildcards
 - MySQL IN Operator
 - MySQL BETWEEN
 - MySQL Aliases
 - MySQL Joins
 - MySQL INNER JOIN Keyword
 - MySQL LEFT JOIN Keyword
 - MySQL RIGHT JOIN Keyword
 - MySQL CROSS JOIN Keyword
 - MySQL Self Join
 - MySQL UNION Operator
 - MySQL GROUP BY Statement
 - MySQL HAVING Clause
 - MySQL EXISTS Operator
 - MySQL ANY And ALL Operators
 - MySQL INSERT INTO SELECT Statement
 - MySQL CASE Statement
 - MySQL NULL Functions
 - MySQL Comments
 - MySQL Operators
 - MySQL CREATE DATABASE Statement
 - MySQL DROP DATABASE Statement
 - MySQL CREATE TABLE Statement
 - MySQL DROP TABLE Statement
 - MySQL ALTER TABLE Statement
 - MySQL Constraints
 - MySQL NOT NULL Constraint
 - MySQL UNIQUE Constraint
 - MySQL PRIMARY KEY Constraint
 - MySQL FOREIGN KEY Constraint
 - MySQL CHECK Constraint
 - MySQL DEFAULT Constraint
 - MySQL CREATE INDEX Statement
 - MySQL AUTO INCREMENT Field
 - MySQL Working With Dates
 - MySQL Views
 - MySQL Data Types
 - MySQL Functions
 
MySQL CHECK Constraint
MySQL CHECK Constraint
The CHECK constraint is used to limit the value range that can be placed in a column.
If you define a CHECK constraint on a column it will allow only certain values for this column.
If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row.
Practice Excercise Practice now
CHECK On CREATE TABLE
The following SQL creates a CHECK constraint on the "Age" column when the "Persons" table is created. The CHECK constraint ensures that the age of a person must be 18, or older:
 
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
CHECK (Age>=18)
);
To allow naming of a CHECK constraint, and for defining a CHECK constraint on multiple columns, use the following SQL syntax:
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
City varchar(255),
CONSTRAINT CHK_Person CHECK (Age>=18 AND City='Sandnes')
);
Practice Excercise Practice now
CHECK On ALTER TABLE
To create a CHECK constraint on the "Age" column when the table is already created, use the following SQL:
 
ADD CHECK (Age>=18);
To allow naming of a CHECK constraint, and for defining a CHECK constraint on multiple columns, use the following SQL syntax:
ADD CONSTRAINT CHK_PersonAge CHECK (Age>=18 AND City='Sandnes');
Practice Excercise Practice now
DROP A CHECK Constraint
To drop a CHECK constraint, use the following SQL:
 
DROP CHECK CHK_PersonAge;
Practice Excercise Practice now
Products
Partner
Copyright © RVR Innovations LLP 2025 | All rights reserved - Mytat.co is the venture of RVR Innovations LLP