

Integrity constraints are a set of rules used by database management systems (DBMS) to ensure the accuracy, consistency, and dependability of data in a database. These rules help maintain the quality of data by ensuring that processes like adding, updating, or deleting information do not harm the integrity of the database. They play an essential role in maintaining the integrity of the database, preventing accidental or intentional corruption of the data.
Organisations depend on clean data for decision-making, consumer behaviour analysis, and market trends assessment. As data volumes within organisations skyrocket and the data is used to make decisions about the company’s future, maximizing data integrity is also more critical.
To achieve data integrity, organisations follow processes including error checking, validation procedures, and strict security measures like encryption, access control, and backup to prevent data loss. Want to learn more about what integrity constraints in DBMS are? This blog explores the role of integrity constraints in DBMS and their types, and outlines their significant benefits. Read on to learn more!
Integrity constraints in a database management system (DBMS) are rules that help to keep the data in the database accurate, consistent, and reliable. Every time there is an insertion, deletion, or update of data in the database, it is the responsibility of these integrity constraints to maintain the integrity of the data.
Integrity constraints are a set of rules that ensure all the information stored in the database follows defined formats, relationships, and conditions. Integrity constraints help prevent accidental data errors, but protecting against unauthorised users is handled by security features like access control.
Integrity constraints play an essential role in DBMS. There are various reasons why integrity constraints is crucial. Let’s see
For example, a simple integrity constraint in a DBMS might state that all students must have a valid unique roll number. This would prevent someone from unexpectedly entering an invalid roll number into the database.
Domain constraints contain a particular set of rules or conditions to restrict the kind of attributes or values a column can hold in the database table. Domains are defined using data types like string, char, time, date, decimal, integer, etc.
Example
Consider a student table with rollno, name, age, and class of students.
In the above student’s table the value A in the last row and last column violates the domain integrity constraints because the Class attribute only accepts integer values, while A is a character.
The domain constraints are essential as they prevent invalid data from entering the database. They ensure each field stays within the expected type and format. They make the database easier to manage and maintain by reducing errors.
Domain constraints can be divided into two categories that control data at the most granular level. They either need specific columns to always contain a value or apply logical tests to ensure each value meets particular conditions.
The domain constraints are essential as they prevent invalid data from entering the database. They ensure each field stays within the expected type and format. They make the database easier to manage and maintain by reducing errors.
Null values are the unassigned values, or we can also say that they are unknown or the missing attribute values, and by default, a column can hold null values. The Not-null constraint prevents a column from accepting NULL values.
The Not Null constraint requires that the fields must always have a non-null value; they cannot be left blank. You cannot insert or update a new record without providing a value for that field.
It defines a condition that each row must satisfy, which restricts the value of a column based on a condition like being within a specific range.
It validates data before it is saved to the column, ensuring it meets the defined conditions. It enforces specific rules or range limits on a column’s data.
Entity integrity constraints revolve around the idea that a primary key cannot contain a null value because a primary key is used to determine an individual row in a relation uniquely.
If the primary key includes a null value, then we cannot identify those rows. A table can contain null values except for the primary key field.
1. Uniqueness
The primary key value must be unique for each row in the table, and no duplicate entries are allowed in the primary key column.
2. NOT NULL
The primary key column cannot contain null values, as every row must have a valid identifier.
Example
It is not allowed because it contains a primary key (Student_id) and a NULL value.
Referential integrity constraints are rules that ensure relationships between tables remain consistent. They need a foreign key in a child table to point to a valid primary key in a parent table or remain empty if no match exists. This ensures the logical connection between related tables in a relational database.
Referential integrity constraints are essential.
Example
Here, in the example block below, the 22nd entry is not allowed because it is not present in the 2nd table.
Key constraints in DBMS focus on columns or sets of columns that uniquely identify each record in the table. These rules are needed for maintaining data integrity and preventing duplicate or ambiguous records.
They also make retrieval and updates smoother since you have at least one reliable point of reference for every row. Key constraints keep your data free from mix-ups and maintain a well-organised structure. Let’s see examples.
This is not acceptable, as all rows must be unique
Key constraints can be classified according to the type of uniqueness or restrictions they implement. Each type addresses a different level of precision in how you track your data.
It states that the primary key attributes need to be unique and not null. The primary key acts as the central identifier for every row in a table.
This makes it simple to locate specific rows and ensure that no rows ever share the same core identifier. When another table references this primary key, you establish a clear link that never points to a duplicated record.
Example.
Here, in the example below, the student_id is the primary key attribute. The data entry of the 4th tuple violates the primary key constraints that are specific to the database schema, and therefore, this instance of the database is not a legal instance
Unique value: each student_id must be unique.
Valid: 103
Invalid: A row with NULL for student_id will be rejected.
A unique key ensures that the values in a column are exceptional, but unlike a primary key, it permits one NULL value.
Not Null: Student_id cannot be Null.
nikita@example.com and shahwat@example.com are valid.
Adding another row with nikita@example.com would result in an error.
Integrity constraints in DBMS offer practical benefits that streamline operations.
IIntegrity constraints like primary keys and foreign keys, check constraints prevent the entry of incorrect, incomplete, or inconsistent data. This ensures that the data within the database is reliable and trustworthy.
Instead of embedding data validation logic within each application module integrity constraints enforce these rules directly within the database. The modularity simplifies application development and maintenance as developers don’t need to worry about redundant validation code.
Help to minimise the probability of having data corruption and types of logical errors.
Integrity constraints offer flexibility when loading data into the database. When data is loaded, the integrity constraints are checked automatically. In other words, if there are any problems with the data, they can be immediately detected or corrected.
Another advantage of integrity constraints is that they give a centralised way to specify rules. Rules must only be defined once, and they can be enforced across the entire database.
Copy and paste below code to page Head section
The four primary types of data integrity are entity, domain, referential, and user-defined. These categories help ensure data accuracy, consistency, and validity within a database system.
Integrity can be defined as doing the right thing all the time and requires adherence to a code of ethical and moral principles. There are three types of integrity: ethical/personal integrity, data or database integrity, and IT/cybersecurity integrity.
The references from a row in one table to another table must be valid. Example of referential integrity constraints in the customer/order database of the company: customer (custID, custname), order (orderID, CustID, orderDate).
In database or database management, common types of data integrity include entity integrity, referential integrity, domain integrity, and user-defined integrity. However, this focus is on data accuracy, consistency, reliability and validity, not legal compliance.
The first is internal integrity, the second is external integrity, and the third is the image of integrity. These are conceptual or philosophical forms of personal integrity.
The advantages of integrity are linked with happiness, confidence, and high self-esteem. Integrity teaches children to take responsibility for the consequences of their actions and helps them make informed decisions about their lives.