Introduction
Let’s get introduced to integrity constraints and data validation.
We'll cover the following
Why we need integrity constraints
In order to detect non-admissible and inconsistent data, and to prevent such data from being added to an application’s database, we need to define suitable integrity constraints. These constraints can be used by the application’s data validation mechanisms to catch cases of flawed data. Integrity constraints are logical conditions that must be satisfied by the data entered by a user and stored in the application’s database.
For instance, if an application is managing data about persons including their birth dates and their death dates, then we must make sure that for any persons record with a death date, this date is not before that person’s birth date.
Since integrity maintenance is fundamental in database management, the data definition language part of the relational database language SQL supports the definition of integrity constraints in various forms. However, there is hardly any support for integrity constraints and data validation in common programming languages such as PHP, Java, C#, or JS. Therefore, it’s important to take a systematic approach to constraint validation in web application engineering. One way to do this is to choose an application development framework that provides sufficient support for it.
Unfortunately, many web application development frameworks don’t provide sufficient support for defining integrity constraints and performing data validation.
Goals of integrity constraints
Integrity constraints should be defined in one central place in an application. They are used for configuring the user interface and for validating data in different parts of the application, such as in the user interface and in the database. Our goal is to use them to do the following:
- Prevent the user from entering invalid data in the user interface (UI) by limiting the input options, if possible.
- Detect and reject invalid user input as early as possible by performing constraint validation in the UI. This is done for those UI widgets where invalid user input cannot be prevented by limiting the input options.
- Prevent invalid data from polluting the application’s main memory state and persistent database state by performing constraint validation in the model layer, as well as in the database.
HTML5 provides support for validating user input in an HTML-forms-based UI. Here, the goal is to provide immediate feedback to the user whenever invalid data has been entered into a form field. This UI mechanism of responsive validation is an important feature of modern web applications. In traditional web applications, the back-end component validates the data and returns the validation results in the form of a set of error messages to the front-end. Only then, in the form of a bulk message does the user get the validation feedback. However, this feedback is slow, often arriving several seconds later.
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy