SQL Server For Beginners Part-III

Database Integrity

Shivani Nalawade
3 min readApr 23, 2020

Data Integrity:

The term data integrity refers to the accuracy and consistency of data.

  • For example, a user could accidentally try to enter a phone number into a Name field. If the system enforces data integrity, it will prevent the user from making these mistakes.
  • Every entity is uniquely identified by a unique non-null attribute of the primary key.
  • Integrity rule that can be enforce on to entities are NULL, UNIQUE and PRIMARY KEY.

Example:

Example of Primary Key
  • Primary key attribute values needs to be unique as well as null values are not allowed in primary key attribute
  • Null represents absence of data, It’s neither zero or Empty because Empty string also have an value(Empty doe’s not represent Null).
  • Maintaining data integrity means making sure the data remains complete and unchanged throughout its entire life cycle. This includes the capture of the data, storage, updates, transfers, backups, etc. Every time data is processed there’s a risk that it could get corrupted (whether accidentally ).

Referential Integrity:

It is a very useful and important part in RDBMS.

  • Referential integrity refers to the accuracy and consistency of data within a relationship between two tables.
  • A referential Integrity is a database concept that is used to build and maintain relationships between two tables avoid the logical corruption data (corruption occur during writing, reading, storage, transmission, or processing, which changes to the original data).
  • The referential integrity constraint is specified between two tables and used to maintain the consistency among tuples(A single row of a table) in two tables
  • For example,suppose Table x has a foreign key that points to a field in Table Y. Referential integrity would prevent you from adding a record to Table Y that cannot be linked to Table X. In addition, the referential integrity rules might also specify that whenever you delete a record from Table X, any records in Table Y that are linked to the deleted record will also be deleted.
  • This is a for saying it formally there are two relations and one relation as a primary key which is used in the other relation as a foreign key then there is a referential integrity that needs to be maintained.
  • where as foreign keys are the columns of a table that points to the primary key of another table.

To better understand this concept please do watch the below video.It will resolve your all doubts:

--

--