For any stored data if we want to preserve the consistency and correctness, a relational DBMS typically imposes one or more data integrity constraints. These constraints restrict the data values which can be inserted into the database or created by a database update.
There are different types of data integrity constraints that are commonly found in relational databases, including the following −
Required data − Some columns in a database contain a valid data value in each row; they are not allowed to contain NULL values. In the sample database, every order has an associated customer who placed the order. The DBMS can be asked to prevent NULL values in this column.
Validity checking − Every column in a database has a domain, a set of data values which are legal for that column. The DBMS allowed preventing other data values in these columns.
Entity integrity − The primary key of a table contains a unique value in each row that is different from the values in all other rows. Duplicate values are illegal because they are not allowing the database to differentiate one entity from another. The DBMS can be asked to enforce this unique values constraint.
Referential integrity − A foreign key in a relational database links each row in the child table containing the foreign key to the row of the parent table containing the matching primary key value. The DBMS can be asked to enforce this foreign key/primary key constraint.
Other data relationships − The real-world situation which is modeled by a database often has additional constraints which govern the legal data values that may appear in the database. The DBMS is allowed to check modifications to the tables to make sure that their values are constrained in this way.
Business rules − Updates to a database that are constrained by business rules governing the real-world transactions which are represented by the updates.
Consistency − Many real-world transactions that cause multiple updates to a database. The DBMS is allowed to enforce this type of consistency rule or to support applications that implement such rules.