Referential integrity
Encyclopedia
Referential integrity is a property of data which, when satisfied, requires every value of one attribute (column) of a relation
Relation (database)
In relational model:A relation value, which is assigned to a certain relation variable, is time-varying. By using a Data Definition Language , it is able to define relation variables.The following is an example of a heading which consists of three attributes....

 (table) to exist as a value of another attribute in a different (or the same) relation (table).

For referential integrity to hold in a relational database
Relational database
A relational database is a database that conforms to relational model theory. The software used in a relational database is called a relational database management system . Colloquial use of the term "relational database" may refer to the RDBMS software, or the relational database itself...

, any field in a table
Table (database)
In relational databases and flat file databases, a table is a set of data elements that is organized using a model of vertical columns and horizontal rows. A table has a specified number of columns, but can have any number of rows...

 that is declared a foreign key
Foreign key
In the context of relational databases, a foreign key is a referential constraint between two tables.A foreign key is a field in a relational table that matches a candidate key of another table...

 can contain only values from a parent table's primary key or a candidate key
Candidate key
In the relational model of databases, a candidate key of a relation is a minimal superkey for that relation; that is, a set of attributes such that# the relation does not have two distinct tuples In the relational model of databases, a candidate key of a relation is a minimal superkey for that...

. 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 system
Relational database management system
A relational database management system is a database management system that is based on the relational model as introduced by E. F. Codd. Most popular databases currently in use are based on the relational database model....

s (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
Data dictionary
A data dictionary, or metadata repository, as defined in the IBM Dictionary of Computing, is a "centralized repository of information about data such as meaning, relationships to other data, origin, usage, and format." The term may have one of several closely related meanings pertaining to...

.
Improved data quality

An obvious benefit is the boost
to the quality of data that is stored in a database. There can still be errors, but at least data references are genuine
and intact.
Faster development

Referential integrity is declared.
This is much more productive (one or two orders of magnitude) than writing custom programming code.
Fewer bugs

The declarations of referential integrity are more concise than the equivalent programming code. In
essence, such declarations reuse the tried and tested general-purpose code in a database engine, rather than redeveloping the same logic on a case-by-case basis.
Consistency across applications

Referential integrity ensures the quality of data references across the multiple
application programs that may access a database.
You will note that the definitions from the Web are expressed in terms of relational databases. However, the principle of referential integrity applies more broadly. Referential integrity applies to both relational and OO databases, as
well as programming languages and modeling.

See also

  • Dangling pointer
    Dangling pointer
    Dangling pointers and wild pointers in computer programming are pointers that do not point to a valid object of the appropriate type. These are special cases of memory safety violations....

  • Declarative Referential Integrity
    Declarative Referential Integrity
    Declarative Referential Integrity is one of the techniques in the SQL database programming language to ensure data integrity.- Meaning in SQL :...

  • Domain/key normal form
    Domain/key normal form
    Domain/key normal form is a normal form used in database normalization which requires that the database contains no constraints other than domain constraints and key constraints....

  • Entity integrity
    Entity integrity
    In the relational data model, entity integrity is one of the three inherent integrity rules. Entity integrity is an integrity rule which states that every table must have a primary key and that the column or columns chosen to be the primary key should be unique and not null.A direct consequence of...

  • Propagation constraint
    Propagation constraint
    In database systems, a propagation constraint "details what should happen to a related table when we update a row or rows of a target table" . Tables are linked using primary key to foreign key relationships...

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK