Home > DeveloperSection > Interviews > What is a "constraint"?

Posted on    October-25-2010 12:00 AM

 MSSQL Server MSSQL Server 
 2 Answer(s)
  1095  View(s)
Rate this:

Pushpendra Singh

Total Post:241

Posted on    November-01-2010 12:00 AM

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. Each type of constraint performs a specific type of action. Default is not a constraint. 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.

Amit Singh

Total Post:565

Posted on    November-09-2010 1:00 AM

A constraint is an expression that specifies the semantics of an element, and it must always be true.
Constraint is a restriction on table.There are two types of 
constraints 1.ananymous constraint and 2.named
constraint.under named and ananymous constraints there are
1.primary key constraint
2.foreign key constraint
3. not null constraint
4. check constraint
5. unique constraint.

Don't want to miss updates? Please click the below button!

Follow MindStick