---
title: "What is a \"constraint\"?"  
description: "What is a \"constraint\"?"  
author: "Pushpendra Singh"  
published: 2010-10-25  
updated: 2020-09-19  
canonical: https://www.mindstick.com/interview/90/what-is-a-constraint  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 2 minutes  

---

# What is a "constraint"?

A constraint allows you to apply simple referential integrity checks to a table. There are four primary types of constraints that are currently supported by SQL Server: PRIMARY/UNIQUE - enforces uniqueness of a particular table column. DEFAULT - specifies a default value for a column in case an insert operation does not provide one. FOREIGN KEY - validates that every value in a column exists in a column of another table. CHECK - checks that every value stored in a column is in some specified list. Each type of constraint performs a specific type of action. Default is not a constraint. NOT NULL is one more constraint which does not allow values in the specific column to be null. And also it the only constraint which is not a table level constraint.

## Answers

### Answer by Amit Singh

A constraint is an expression that specifies the semantics of an element, and it must always be true.

## Constraint is a restriction on table.There are two types of

constraints 1.ananymous constraint and 2.named

constraint.under named and ananymous constraints there are

1.primary key constraint

2.foreign key constraint

3. not null constraint

4. check constraint

5. unique constraint.

\
\

\

\

### Answer by Pushpendra Singh

A constraint allows you to apply simple referential integrity checks to a table. There are four primary types of constraints that are currently supported by SQL Server: PRIMARY/UNIQUE - enforces uniqueness of a particular table column. DEFAULT - specifies a default value for a column in case an insert operation does not provide one. FOREIGN KEY - validates that every value in a column exists in a column of another table. CHECK - checks that every value stored in a column is in some specified list. Each type of constraint performs a specific type of action. Default is not a constraint. NOT NULL is one more constraint which does not allow values in the specific column to be null. And also it the only constraint which is not a table level constraint.


---

Original Source: https://www.mindstick.com/interview/90/what-is-a-constraint

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
