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!

What is an Integrity constraint?

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.

Why are integrity constraints important?

Integrity constraints play an essential role in DBMS. There are various reasons why integrity constraints is crucial. Let’s see

  • Data stays accurate: Just imagine entering data in the wrong format. With integrity constraints, errors get flagged immediately. Without these rules, we might end up with incorrect information. This saves lots of time and possibe headaches later. 
  • Data consistent: For example, if one table references another table constraints make sure that the relationships stay valid. Reduce the chances of having conflicts or duplicate records in the data entries. 
  • Data reliability: By preventing invalid data entries we trust that the data we have holds only valid information. This is important for decision-making and reporting.
  • Data validation: They enforce specific rules for data entry guaranteeing every piece of information meets our standards. This means our database remains a dependable resource. 

Integrity constraints in DBMS with an example

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.

Types of Integrity constraints

1. Domain constraints

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.

Roll No Name Age Class
101Deva158
102Rupal 146
103Steve 84
104Bruce 18

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. 

Types of domain constraints

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. 

1. Non-null constraint

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.

2. Check constraint

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.

3. Entity integrity constraints

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. 

The key points of entity integrity constraints are

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.

Student ID Name StandardAge
101Ramesh5th20
102Kamlesh5th21
103Mukesh5th22
NULLkapil5th20

4. Referential integrity constraints

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.

  • Maintains consistency: Ensure relationships between tables are valid.
  • Prevents orphan records: Avoid cases where a record in a child table references a non-existent parent record.
  • Enforces logical relationships: Build up the logical structure of the relationship database.

Example

Here, in the example block below, the 22nd entry is not allowed because it is not present in the 2nd table.

Studentid NamestandardBlock_no
101Aakash5th22
102Mukesh6th20
103Ramesh2nd21

Block_noBlock location
21Chandigarh
20punjab

5. Key constraints

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.

Student_idNameStandard Age
101Ramesh 5th20
102kalpesh5th21
103Mukesh5th22
104Aakash5th20

This is not acceptable, as all rows must be unique

Types of key constraints

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.

1. Primary key constraints

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.

Student_id NameStdAge
101Reena5th20
102Neena5th21
103Meena5th22

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.

  • 101,102, 103 are valid
  • Inserting 101 again would result in an error.

Valid: 103

Invalid: A row with NULL for student_id will be rejected.

2. Unique key constraints

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.

Employee_idEmailName
1nikita@example.comNikita Shastri
2NULLShahwat Hiren
3shahwat@example.comManoj sharma

Unique values: The email column can contain one NULL value.

nikita@example.com and shahwat@example.com are valid.

Adding another row with nikita@example.com would result in an error.

Benefits of  Integrity constraints

Integrity constraints in DBMS offer practical benefits that streamline operations.

1. Data Accuracy and consistency

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. 

2. Reduced application complexity

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. 

3. Error prevention

Help to minimise the probability of having data corruption and types of logical errors. 

4. Flexibility during loading

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. 

5. Centralized rules

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.

Disadvantages of Integrity constraints in DBMS?

  • Increased design complexity: Implementing complex constraints can make database schema design more challenging.
  • Requires more maintenance: Changes to constraints might necessitate updates to application code or other database objects.
  • Limited flexibility: Constraints can restrict the type of data that can be entered, potentially limiting flexibility in specific scenarios.

Difference between database-level vs. application-level enforcement of DBMS constraints

Database LevelApplication Level
Faster as rules execute closer to the dataSlower due to additional processing in the app.
Ideal for enforcing universal rules like key constraints Suitable for complex, app-specific validations
Centralized, easier to manage changesDistributed across applications, harder to update
Block invalid data at the sourceError may slip through application loopholes.

FAQ's

👇 Instructions

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.

Ready to Master the Skills that Drive Your Career?
Avail your free 1:1 mentorship session.
Thank you! A career counselor will be in touch with you shortly.
Oops! Something went wrong while submitting the form.
Join Our Community and Get Benefits of
💥  Course offers
😎  Newsletters
⚡  Updates and future events
undefined
undefined
Ready to Master the Skills that Drive Your Career?
Avail your free 1:1 mentorship session.
Thank you! A career counselor will be in touch with
you shortly.
Oops! Something went wrong while submitting the form.
Get a 1:1 Mentorship call with our Career Advisor
Book free session
a purple circle with a white arrow pointing to the left
Request Callback
undefined
a phone icon with the letter c on it
We recieved your Response
Will we mail you in few days for more details
undefined
Oops! Something went wrong while submitting the form.
undefined
a green and white icon of a phone