Explain check constraint with example
In : IMCA Subject : Introduction to RDBMSA CHECK constraint is used in SQL to limit the values that can be inserted or updated in a column of a table. It ensures that all values in a column satisfy a specific condition.
If the condition evaluates to TRUE , the value is accepted. If it's FALSE or UNKNOWN , the operation (like INSERT or UPDATE) fails.
Example :
CREATE TABLE Persons (
ID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT CHECK (Age >= 18)
);
INSERT INTO Persons (ID, Name, Age) VALUES (1, 'John', 20);