0 votes
1 view
in SQL by (31.4k points)

Can anyone explain the check constraint in MySQL?

1 Answer

0 votes
by (73.7k points)

In MySQL, CHECK constraint allows us to limit the value range that can be inserted in a column.

If you define a CHECK constraint on a single column, we can insert only certain values in this column.

If you define a CHECK constraint on a table it allows us to limit the values that can be inserted in certain columns based on values in other columns in the row.

Here is an example of how to limit the values to less than 18 in Age column:

CREATE TABLE Persons (
    ID int NOT NULL,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Age int,
    CHECK (Age>=18)
);

If you want to learn MySQL from top professionals, I recommend this SQL Course by Intellipaat.

Also, watch this video on MySQL:

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jun 26 in SQL by Sudhir_1997 (31.4k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...