Database integrity refers to the accuracy or correctness of data in a database. Before deep diving into database integrity, ensure that you have gone through following article:
To enure the data integrity, constraints come into the picture. Constraints are rules applied on the data so as to ensure data integrity.
For example, let us say we have a table employee having columns Emp_Id, Name, Address, Pincode, and Salary. We may have many constraints on the table:
All these are constraints on the data. Constraints are decided based on rules and demands of the business.
Keys are vital part of database and used to apply various types of constraints on the database. A key is a minimal set of columns that uniquely identifies or functionally determines every column value in a row.
Consider Employee table as discussed above, here Emp_Id is the key as it uniquely identifies a row in a table.
Various types of Keys:
Student_Id is primary key in Student table
Class_Id is primary key in Class table.The concept of foreign key comes in to picture when we want to establish relationship between table SC and Student as well as Class tables. For a given Student_Id in SC table, there must be exactly one student row in the Student table. Similarly, for a given Class_Id in SC table, there must be exactly one class row in the Class table. Thus Student_Id and Class_Id are foreign keys in SC table. There can be multiple entries for same Class_Id in SC table, thus foreign key can have same value in a table.
From practical point of view, the most significant keys are Primary key and Foreign key.
Download as PDF
Read next: RDBMS – Entity Integrity and Referential Integrity ››
« Back to Course page
Punjab Civil Services 2021