Pages

Men

rh

10/29/2013

Constraints in SQL Server

Constraints:- Constraints are ANSI- standard method of enforcing the data integrity. Each type of data integrity - domain, entity, and referential - is enforced by using separate types of  constraints.

Constraints ensures valid data values are entered in column and that the value are entered in a column and that relationship between tables are maintained.

Various types of Constraints:-

  • Domain Integrity
  • Referential Integrity
  • Entity Integrity

Domain Integrity:-

  • Default  Constraints
  • Check  Constraints
  • Foreign Key Constraints
  • Null Constraints


Default  Constraints;-  Specifies the default value for the column when an Insert statement does not provide a value.

Check Constraints:- Specifies that data values that are accepatable in a column.

Foreign Key Constraints:- Specifies the data values that are acceptable to update based on values in a column in a another table.

Null Constraints:- Specifies whether  the value of a column can be null.


Referential Integrity:-
  • Primary Key Constraints
  • Unique Constraints

Primary Key Constraints:-It identifies each row uniquely.  It ensures, that users do not enter duplicate values and that Index is created to enhance the performance. Null values are not allowed.

Unique Constraints:-  It prevents duplicate of alternate keys and ensures that an Index is created to enhance the performance. Null values are allowed.

Entity Integrity:-

  • Foreign Key Constraints
  • Check Constraints

Foreign Key Constraints:- Defines a column or combination of columns with values  that match the Primary Key of the same or another table.

Check Constraints:- Specifies the data values that are acceptable in a column based on  values in other columns in the table.







No comments :

Post a Comment