ITP

IMCA - Introduction to RDBMS

Explain check constraint with example

In : IMCA Subject : Introduction to RDBMS

A 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);

About us

A truly open platform where you may ask questions and get answers. We also provide comprehensive and easy-to-understand answers to question papers.  discover...

Site status

Flag Counter

Privacy Policy

Sitemap