Google News
logo
SQL Server - Interview Questions
What is CHECK constraint?
CHECK constraint is applied to any column to limit the values that can be placed in it. It helps to enforce integrity in the database.
Suppose, your website caters to users between age 18 and 60 years. You can use CHECK to ensure that users who are creating an account have age in that range.
CREATE TABLE Users (
    id int NOT NULL,
    first_name varchar(255) NOT NULL,
    last_name varchar(255) NOT NULL,
    age int CHECK (age >= 18 AND age <= 60)
);
Advertisement