Check Constraint :
It is used alongside relational operators to check whether a value satisfies the condition or not (boolean). If the condition is satisfied, the boolean expression sets to True otherwise False. The check constraint does not have a specific syntax. It is used along with the create table syntax.
Syntax :
Create table Marks name varchar2(30), rollnumber number primary key, marks int check (marks<=75)
A table named Student is created along with the condition that marks must not be greater than 75. A user inserts a few values as shown below –
Table – Marks
| Name | Rollnumber | Marks |
|---|---|---|
| Aisha | 111 | 60 |
| Naina | 112 | 73 |
The values are inserted as per the conditions mentioned in the create table syntax. The user tries inserting a few more values yet errors occur as shown below –
Example-1:
Insert into Student
values('Maya', '117', '80')
Output –
The value results in an error as the value is greater than 75.
Example-2:
Insert into Student
values('Maya' '111', '74')
Output –
An error is displayed. This is due to the primary key used for rollnumber. Primary key forbids the use of duplicates in a table.
Check constraint in case of NULL :
Insert into Student
values('Riya', '112', 'NULL')
Output –
In SQL, NULL is used incase of unknown value. Therefore it is considered as False.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
Recommended Posts:
- Unique Constraint in MS SQL Server
- SQL | CHECK Constraint
- SQL | UNIQUE Constraint
- SQL | DEFAULT Constraint
- Foreign Key constraint in SQL
- Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
- Neo4j Create Constraint
- Check whether a Table exists in SQL Server database or not
- Delete statement in MS SQL Server
- SQL Server Mathematical functions (SQRT, PI, SQUARE, ROUND, CEILING & FLOOR)
- SQL Server Identity
- SQL SERVER | Conditional Statements
- SQL Server | STUFF() Function
- SQL Server | SERVERPROPERTY()
- Mean and Mode in SQL Server
- Allow only alphabets in column in SQL Server
- SQL SERVER | IN Condition
- Reverse Statement Word by Word in SQL server
- Copy tables between databases in SQL Server using Import-and-Export Wizard
- Difference between MySQL and MS SQL Server
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

