What are different Types of Constraints Available in SQL Server - SQL Server / T-SQL Tutorial Part 50

What are Constraints in SQL Server?


In simple words, Constraints define rules those we implement to avoid insertion of any data that does not follow the rule.
By using the Constraint, we can validate the data and if complies the rule, It will be inserted in table otherwise rolled back.
Constraints are used to maintain Data Integrity. They make sure the data entered follow the rules we have defined.

There are different types of Constraints available in SQL Server.



  1. Not Null Constraint
  2. Check Constraint
  3. Default Constraint
  4. Unique Constraint
  5. Primary Key Constraint
  6. Foreign Key Constraint


2 comments:

  1. I Have one doubt different beetween primary key and unique key

    ReplyDelete
  2. A primary key constraint establishes a referential integrity between two tables. A primary key only can become foreign key to another table.
    Though PK and UK both store unique values, there are few differences listed below:
    a. Primary constraint does not allow NULL values. This constraint is always non nullable.
    b. Unique key can allow only one NULL value by default; but we can create a filtered unique index to include multiple null values.

    ReplyDelete