Data Integrity Rules:
Definition and explanation:
Data integrity refers to the correctness and
consistency of data. It is another form of database protection or security.
Security involves protecting the data from unauthorized operations, while
integrity is concerned with the quality of data itself. The data integrity plays
very important role in RDBMS, in which multiple users access the data from
database.
Integrity is usually expressed in terms of
certain constraints, These are the consistency rules that can be applied to
database so that the correct data can be entered into database. The constraints
may be applied to individual data items within a single record or they may be
applied to relationships between records. Integrity rules/constraints check the
data that is entered or modified into the database, the examples of integrity
constraints are:
- 'Issue Date' of a book in a library system
cannot be later than the corresponding 'Return Date' of a book.
- Maximum obtained marks in a subject cannot
exceed 100 and less than 0.
- The value of attribute "Gender" for each
record of student table must be "Male" or "Female".
- The records of a table must be unique.
Important data integrity rules are:
(i) Entity integrity
(ii) Domain integrity
(iii) Referential integrity
(i) Entity Integrity:
The entity integrity constraint states that in a
relation no primary key value can have a null value. Entity, integrity
constraint is also referred to as uniqueness constraint. By definition, a
primary key is used to identify tuples uniquely. If two or more tuples have null
values in the primary key attribute, then you can not identify tuples uniquely.
(ii) Domain integrity:
A domain represents a set of values that can be
assigned to an attribute. Domain integrity constraint is specified on the column
(attribute) of a relation, so that correct values can be entered in the column
for each record.
You can specify domain for an attribute into DBMS
or into application code. For example, in Ms-Access, you can specify the. value
of 'Marks' attribute of "Student" table which must be greater than 0 and less
than or equal to 200 as shown in figure below.

In the above figure, you have applied the domain
constraint to the 'Marks' attribute. In the "Field Properties" section, the
property labeled with "Validation Rule" is used to specify the domain
constraint. It is specified by using the expression 0 >= 200 AND <= 200 as shown
above. You can also specify the text for message in the "Validation Text" field,
which will be displayed if user does not follow the domain rule. Suppose you
enter the text "Invalid marks of student", the message1 displayed is shown in
figure below.

(iii) Referential integrity:
The referential integrity constraint is specified
between two relations and is used to maintain the consistency among tuples of
two relations. Referential integrity is applied on foreign keys.
Referential integrity states that if a foreign
key exists in a relation, then the foreign key value must match the primary key
value of some tuple in its home relation (parent relation) or the foreign key
value must be completely null.
Referential integrity ensures that the
relationships between records in related tables remain consistent. For example,
if the relationship between "Student" table and "Marks" table is created then
the DBMS will not allow you to delete record from the ''Student" table if there
is a record related to that student in the "Marks" table.

In 'Student' table, the 'Roll-No' attribute is
used as primary key. Similarly, the 'Roll-No' attribute is used as foreign key
in 'Marks' table. The referential integrity is implemented by primary key and
foreign key relationship. The records in 'Student' table cannot be deleted, if
the related records exist in 'Marks' table.
|