top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

What is the use for CHECK constraint in SQL?

+1 vote
79 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 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 by Siddhi Patel
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...