Introduction to Constraints, Assertions, and Triggers

Helene
Geek Culture
Published in
9 min readJun 7, 2021

--

When you create a database, it usually with a few core goals in mind: to store data in an easy manner, and to be able to easily access or manipulate it. For the latter, this could for example be to insert new data into the database or delete useless and outdated data. However, one of the challenges that arise when we want to modify our database — that we may violate the integrity constraints of the database. To avoid violating these constraints, it is possible to use multiple methods. In this article, we will discuss the methods called ‘constraints’, ‘assertions’, and ‘triggers.

Presenting the Integrity Constraints

Before we dive into the three methods stated above, we should first consider the concept of ‘integrity constraints’ a little bit. Integrity constraints are a set of rules, and they are used to maintain the quality of the information in our database. The integrity constraints assure that when we perform, for example, data insertion or deletion, the data integrity is not violated. In short, integrity constraints are put in place to protect the database against accidental damage. There exist multiple types of integrity constraints, all of which can be seen in the visualization below:

We can try to go through the different types to understand what they mean:

--

--