
When two or more tables have a relationship, we have to ensure that the foreign key value matches the primary key value at all times. Referential integrity is concerned with relationships. The primary key field contains a unique identifier – no two rows can contain the same unique identifier. To achieve this, a primary key can be defined. In the database world, data integrity is often placed into the following types:Įntity integrity defines each row to be unique within its table. Some of these require other (non-database related) factors to be present, such as an offsite backup location, a properly functioning IT network, proper training, security policies, etc. Many of these risks can be addressed from within the database itself (through the use of data types and constraints against each column for example, encryption, etc), while others can be addressed through other features of the DBMS (such as regular backups – and testing that the backups do actually restore the database as expected). It’s not hard to think of many more scenarios where data integrity is at risk.
#DATA INTEGRITY UPDATE#
A user tries to update a primary key value when there’s already a foreign key in a related table pointing to that value.A user tries to delete a record in a table, but another table is referencing that record as part of a relationship.While transferring data between two databases, the network went down.While transferring data between two databases, the developer accidentally tries to insert the data into the wrong table.A bug in an application attempts to delete the wrong record.A user tries to enter a phone number in the wrong format.


Some more examples of where data integrity is at risk: Every time data is processed there’s a risk that it could get corrupted (whether accidentally or maliciously). This includes the capture of the data, storage, updates, transfers, backups, etc. Maintaining data integrity means making sure the data remains intact and unchanged throughout its entire life cycle.
#DATA INTEGRITY HOW TO#
When creating databases, attention needs to be given to data integrity and how to maintain it. A good database will enforce data integrity whenever possible.įor example, a user could accidentally try to enter a phone number into a date field. If the system enforces data integrity, it will prevent the user from making these mistakes. The term data integrity refers to the accuracy and consistency of data.
