SQL Constraints

To set specific rules on the data in a table column we will use SQL Constraints. When DML (Insert, Update, Delete) operation is performed on the table data, SQL server will check the constraints and it will not allow to perform the operation if the data not satisfies the constraints.

SQL server supports the following type of constraints.

1. NOT NULL : Column cannot store NULL value.

2. CHECK : Column data satisfies the specified condition.

3. UNIQUE : Column data contains different values (will not allow duplicate value).

4. PRIMARY KEY : Combination of UNIQUE and NOT NULL. Column cannot have NULL and duplicate value.

5. FOREIGN KEY : Allows data having reference with another table. Also allow NULL values.

6. DEFAULT : Insert a default value for the column when no data specified.