What do we do to attain entity integrity?
Attaining Entity Integrity: The entity integrity can be attained by specifying primary key in a relation. When a primary key constraint is specified on a relation, the DBMS automatically applies the entity integrity on the attribute that is used as primary key.
The attribute cannot contain null value in it. DBMS displays an error message if the user attempts to save a record without specifying a valid value in the primary key attribute if the user specifies composite primary key, the entity integrity is also applied to all attributes that are part of composite primary key.
How referential integrity can be achieved?
Achieving Referential Integrity
The referential integrity can be achieved by connecting two relations by specifying relationship between them. When two relations are connected, one relation is called parent relation and the other is called dependent relation.
The parent relation contains the primary key and dependent relation contains foreign key. A value entered in foreign key attribute in dependent relation must exist in the primary key attribute of parent table.
The record is not stored in the database if the user violated of this rule. In this way, the referential integrity is achieved. It ensures that the data in both relations is consistent.