Thursday 20 March 2014

constraints in sql

To maintaining the integrity of data into database. Their are mainly three type  of constraint.
 1. Entity Constraint.
2. Domain Constraint.
3. Referential integrity constraint.


 Domain Constraint:  Domain constraints deals with one or more columns.
 It is ensuring that a particular column or set of column meets particular criteria. When we insert or update row, the constraints is applied without respect to any other row and table. This kind of constraints is dealing with check constraints, rule, defaults and default constraints.

Entity Constraints : Entity constraints are all about individually rows. This form of constraints doesn't really core about a column as a whole; its inserted in a particular row & would best be exemplified by a constraints that requires every row to have a unique value for a column or combination of problem. We will see this kind of constraints in dealing with primary key and unique constraints.

Referential Constraints :  Referential integrity constraints are created when a value in one column must match the value in other column in either in same table or far more typically a different table.


Default Constraints : A default constraint like all constraints, become an integral part of table definition. It defines what to do when a new row is inserted that doesn't include data for the col um on which you have default constraints. You can defined it as a literal value. e.g setting a default salary to zero or unknown for a string column.

No comments:

Post a Comment