English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

How to Add Check Constraints to a Table in MySQL?

To add a check constraint to the table, let's first create a table.

CREATE table yourTableName (
   Column_name1 datatyep,
   .
   .
   .
   .
   Column_name N datatype,
   check( condition)
);

The following is a method to check age by creating a check constraint.

check(Age>=45)

Now let's create a table and add the age check constraint displayed above when creating the table.

mysql>CREATE table addCheckConstraintDemo
-> (
-> Age int,
-> check(Age>=45)
-> );