---
title: "Which constraints we can use while creating a database in SQL?"  
description: "Which constraints we can use while creating a database in SQL?"  
author: "Anonymous User"  
published: 2019-09-26  
updated: 2019-09-26  
canonical: https://www.mindstick.com/forum/105382/which-constraints-we-can-use-while-creating-a-database-in-sql  
category: "mssql server"  
tags: ["sql server", "sql", "sql server 2008"]  
reading_time: 2 minutes  

---

# Which constraints we can use while creating a database in SQL?

Which [constraints](https://www.mindstick.com/forum/34816/what-is-mapping-constraints-in-database-management-system) we can use [while creating](https://www.mindstick.com/forum/156748/why-do-we-use-sql-constraints-which-constraints-we-can-use-while-creating-a-table-in-sql) a [database in SQL](https://www.mindstick.com/forum/158348/how-do-you-create-a-new-database-in-sql-server)?

## Replies

### Reply by Shrikant Mishra

The constraints are used to set the rules for all records in the table. Although any constraints get violated then it can abort the action that caused it.

The constraints are defined while creating the [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) itself with CREATE TABLE statement or even after the table is created once with the ALTER TABLE statement.

These are 5 major constraints are used in [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database), such as

**NOT NULL:** This indicates that the column must have some value and cannot be left null

**UNIQUE:** These constraints are used to ensure that each row and column has unique value and no value is being repeated in any other row or column

**PRIMARY KEY:** These constraints are used in association with NOT NULL and UNIQUE constraints such as on one or the combination of more than one columns to identify the particular record with a unique identity.

**FOREIGN KEY:** This is used to ensure the referential integrity of data in the table and also matches the value in one table with another using Primary Key

**CHECK:** This is used to ensure whether the value in columns fulfills the specified condition


---

Original Source: https://www.mindstick.com/forum/105382/which-constraints-we-can-use-while-creating-a-database-in-sql

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
