what is referential integrity

what is referential integrity

1 year ago 30
Nature

Referential integrity is a property of data that ensures that all references are valid. It is a constraint on the database design that makes sure that each foreign key in a table points to a unique primary key value in another table. In other words, referential integrity requires that whenever a foreign key value is used, it must reference a valid, existing primary key in the parent table.

For referential integrity to hold in a relational database, any column in a base table that is declared a foreign key can only contain either null values or values from a parent tables primary key or a candidate key. If a foreign key value is used, it must reference a valid, existing primary key in the parent table. For instance, deleting a record that contains a value referred to by a foreign key in another table would break referential integrity.

Some relational database management systems (RDBMS) can enforce referential integrity, normally either by deleting the foreign key rows as well to maintain integrity, or by returning an error and not performing the delete. Which method is used may be determined by a referential integrity constraint defined in a data dictionary.

Referential integrity is important because it ensures that all data in a database remains consistent and up-to-date. It helps to prevent incorrect records from being added, deleted, or modified. A lack of referential integrity in a database can lead to incomplete data being returned, usually with no indication of an error.

In summary, referential integrity is a system of rules that ensures data from one table matches with data in another table. It is a constraint on the database design that makes sure that each foreign key in a table points to a unique primary key value in another table. It helps to ensure that all data in a database remains consistent and up-to-date, and it prevents incorrect records from being added, deleted, or modified.

Read Entire Article