Sunday 14 July 2013

Database Constraint

Database Constraint is user-defined structures that express the behaviors of column. It is used to protect wrong entry. There are five types of database constraints. Such

  1. Primary Key Constraint
  2. Foreign Key Constraint
  3. Unique Key Constraint
  4. Not null Constraint
  5. Check Constraint

Primary Key Constraint
A column value will be unique among all the rows in a table. It does not allow any null value. Therefore, a primary key constraint has the behaviors of both Not Null and Unique Key Constraints.

Foreign Key Constraint
We can’t insert a foreign key value which is not present in the primary key column of that foreign key.



Unique Key Constraint
A column value will be unique among all the rows in a table. It allows only a single Null value in that column. Depending on the design, a table may have more than one unique key constraint.

Not null Constraint
It makes a column mandatory. This means you can’t insert a row in the table without providing a valid data.

Check Constraint
Check Constraints are table-level constraint. It doesn’t make the column mandatory.


EmoticonEmoticon