How can we help you?

We have hundreds of highly-qualified, experienced experts working in 70+ technologies.

IBM i e-Book

A Developer’s Guide to Mastering IBM i Concepts

System Architecture

Relational Database Integration

In Database Management System, integrity constraints are pre-defined set of rules that are applied on the table fields to ensure that the integrity, consistency, and validity of the data present in the database table.

Every time a table insert, update, delete, or alter operation is performed, evaluation of all the conditions or rules mentioned in the integrity constraint will be done. The data can be inserted, updated, deleted, or altered only if the result of the constraint comes out to be True. By this, these are useful in preventing any damage to the database by an authorized user.

Types of integrity constraints:
  • Domain Constraint
  • Entity Constraint
  • Referential Integrity Constraint
  • Key Constraint

Domain Constraint

Domain constraints can be defined as a set of rules that are valid for an attribute. The domain’s data type includes character, integer, time, string etc. The value must be in the corresponding domain of the attribute.

Example:
Name Class Age
Prakash 6 11
Ravi 7 12
Rajesh 6 11
Nikhil 7B 13

In the above table, we can see the Class column, the data type of the domain is an integer, but the attributes data type is a character. This is a violation, so it will not allow.

Here, we tried giving Class column value in Characters.

As we can see, it didn’t insert the record since the Class column is an Integer type.

Entity Constraint

Entity Integrity Constraint is used to ensure that the primary key cannot be null. A primary key is used to identify individual records in a table and if the primary key has a null value, then we can’t identify those records. In a relation, there can be null values, but they must be not the primary key.

Example:
Roll No Name Class
1 Nikhil 9
2 Prasanth 9
3 Anil 9
Siddharth 9

In the above table, The Roll No column has the Null value in the last row. So, it cannot be assigned as the primary key.

Referential Integrity Constraint

Referential Integrity Constraint ensures that there must always exist a valid relationship between two relational database tables. This constraint is defined between two tables. This valid relationship between the two tables confirms that a foreign key exists in a table. It should always reference a corresponding attribute in the other table or be null.

Example:

Table A

Roll No Name Class Subject Code
6 Gowtham 10 4243
7 Chandu 10 9876
8 Naveen 10 0123
9 Rajeev 10 8976

Table B

Subject Code Subject
4243 Maths
9876 Physics
0567 Chemistry
8976 Social

Here, we can see that in Table A, Subject Code 0123 is not valid, as this value is not defined in the Table B and the column is assigned as the primary key, and Subject Code in table A is assigned as the Foreign Key.

Key Constraint

In Database, a key is used to uniquely identify an entity in an entity set. There could be multiple keys in a single entity set, but out of these multiple keys, only one key will be the primary key. A primary key can only contain unique and not null values in the relational database table.

Example:
Roll No Name Class
1 Nikhil 9
2 Prasanth 9
3 Anil 9
2 Siddharth 9

In the above table, Roll No cannot be defined as a primary key because it contains a duplicate value. That Roll No column row must contain unique values.

How can we help you?

We have hundreds of highly-qualified, experienced experts working in 70+ technologies.

X

Awards and Certifications

company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo