Tuesday, September 28, 2010

What is a “constraint” in SQL?

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.
* 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.

No comments:

Post a Comment