CHECK
CHECK constraint is a condition defined to a column or a table to limit the value that can be inserted into it.
For instance, in our students table, let us assume that we had another column "Age". The minimum age requirement for this class is 16. So to ensure that the age of a student is atleast 16, we define CHECK constraint in the table students as follow:
CREATE TABLE students (
student_id INT NOT NULL,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
email varchar(255),
age INT NOT NULL,
CHECK (Age >= 16)
);
What if the table was already created?
We use ALTER TABLE statement as follow
ALTER TABLE students
ADD CHECK (Age >= 16);