Referential Integrity

Referential integrity is a property of data which, when satisfied, requires every value of one attribute () of a () to exist as a value of another attribute in a different (or the same) relation (table).

For referential integrity to hold in a , any field in a table that is declared a can contain only values from a parent table's or a . For instance, deleting a record that contains a value referred to by a foreign key in another table would break referential integrity. This means that you cannot a primary key record while there are still records in the foreign key table point to the primary key .

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. When the database deletes the foreign key records automatically when the primary key is removed, the process is called a cascade delete. This is not encouraged for the beginner working with . Typically a database will not perform a cascade deleted unless explicitly given the command. Usually the delete will not be executed if the system detects a referential integrity constraint violation.

In conclusion if referential integrity is being enforced in a database system, a primary key row cannot be removed from a table in referential key rows from another tables are associated with the primary key record. Additionally, a foreign key row cannot be inserted into a foreign key table is the primary key row is not inserted into the primary key table first. In the context of our discussions, a customer cannot be deleted from the cleaner’s database while the customer has material not picked up. A person accepting articles of clothing from a customer cannot input the each article of clothing for the customer, if the customer’s information has not been entered first.

Later we will discover that the same sequence must be maintained when creating and deleting tables as well.