top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the use for CHECK constraint in SQL?

+1 vote
1,267 views
What is the use for CHECK constraint in SQL?
posted Jun 30, 2018 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

3 Answers

0 votes

The CHECK constraint is used to limit the value range that can be placed in a column. If you define a CHECK constraint on a single column it allows only certain values for this column.If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row.

answer Jun 30, 2018 by Madhavi Latha
0 votes

The CHECK Constraint allows you to specify a condition on a row of the table.
If the condition is True then it will allow to enter data into the table otherwise the data won't be entered into the table.

Following is an example how Check Constraint is used:

Create Table Student(
ID int, Name varchar(20),
Age int Check(Age>=18),
);
answer Mar 19, 2019 by Drasti Chavda
0 votes

The CHECK constraint is used to limit the value range that can be placed in a column.
If you define a CHECK constraint on a single column it allows only certain values for this column.
If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row.

Query:

CREATE TABLE Persons (
    ID int NOT NULL,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Age int,
    City varchar(255),
    CONSTRAINT CHK_Person CHECK (Age>=18 AND City='Sandnes')
);
answer Apr 10, 2019 by Siddhi Patel
...