Integrity Rules and Constraints - Database Design Fundamentals For Software Engineers
Integrity Rules and Constraints - Database Design Fundamentals For Software Engineers
There are many types of integrity constraints, but we will focus on the
following:
Domain constraints
https://www.educative.io/courses/database-design-fundamentals/gxN1XONDovG 1/5
26/7/23, 18:32 Integrity Rules and Constraints - Database Design Fundamentals for Software Engineers
Domain constraints specify that within each tuple, the value of each
attribute must appear in the corresponding domain (in other words, it
should belong to the appropriate data type). We have already discussed how
domains can be specified in the previous lessons. The data types associated
with domains typically include integers, real numbers, characters, booleans,
etc. Let’s consider the following example:
Here, value ‘A’ is not allowed since only integer values can be taken by the
Age attribute.
Entity integrity
https://www.educative.io/courses/database-design-fundamentals/gxN1XONDovG 2/5
26/7/23, 18:32 Integrity Rules and Constraints - Database Design Fundamentals for Software Engineers
This relation does not satisfy the entity integrity constraint as here the
primary key contains a NULL value.
This constraint is enforced when a foreign key references the primary key of
a relation. It specifies that all the values taken by the foreign key must either
be available in the relation of the primary key or be NULL.
Dep_No Dep_Name
D1 Physics
D4 Biology
D5 Computer Science
D7 Electrical Engineering
Now we insert the following tuple into the STUDENT table; <4, ‘Anderson’,
‘D9’>
https://www.educative.io/courses/database-design-fundamentals/gxN1XONDovG 3/5
26/7/23, 18:32 Integrity Rules and Constraints - Database Design Fundamentals for Software Engineers
We now see that the STUDENT relation does not satisfy the referential
integrity constraint. This is because, in the DEPARTMENT relation, no value
of a primary key specifies department no. 9. Hence, the referential integrity
constraint is violated.
Now if we try to delete the tuple in the DEPARTMENT relation with Dep_No =
‘D1’. This will again violate the referential integrity constraint, as some
students are already enrolled in the course and this will lead to
inconsistencies in the database.
Key constraints
The key constraint is violated as the primary key Std_Id has the same value
for the first and fourth tuple.
In the next lesson, we will define what a relational database schema is and
how it is used to represent integrity constraints.
Back Next
Introduction to Databa…
Relational Database S…
Mark as
Completed
https://www.educative.io/courses/database-design-fundamentals/gxN1XONDovG 5/5