Integrity Constraints

These are a set of rules. It is used to maintain the quality of information. Integrity constraints ensure that data integrity is not affected due to insertion, deletion, updating, and other processes. 
Thus, integrity constraints are used to guard against the accidental damage of the database.  


TYPES OF INTEGRITY CONSTRAINTS


Various types of integrity constraints are-
  1. Domain Integrity
  2. Entity Integrity Constraint
  3. Referential Integrity Constraint
  4. Key Constraints

1. Domain Integrity- Domain integrity means the definition of a valid set of values for an attribute. You define a data type, length, or size, is null value allowed, is the value unique or not for an attribute, the default value, the range (values in between), and/or specific values for the attribute. 

2. Entity Integrity Constraint- This rule states that in any database relation value of attribute of a primary key can't be null.

3. Referential Integrity Constraint-It states that if a foreign key exists in a relation then either the foreign key value must match a primary key value of some tuple in its home relation or the foreign key value must be null.

The rules are:
1. You can't delete a record from a primary table if matching records exist in a related table.
2. You can't change a primary key value in the primary table if that record has related records.
3. You can't enter a value in the foreign key field of the related table that doesn't exist in the primary key of the primary table.

4. Key Constraints- A Key Constraint is a statement that a certain minimal subset of the fields of a relation is a unique identifier for a tuple.
There are 4 types of key constraints-
  1. Candidate key.
  2. Super key
  3. Primary key
  4. Foreign key

Post a Comment

0 Comments