Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Referential integrity
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Where all data references are valid}} [[File:Referential integrity broken.png|thumb|350px|An example of a database that has not enforced '''referential integrity'''. In this example, there is a foreign key (<code>artist_id</code>) value in the album table that references a non-existent artist β in other words there is a [[foreign key]] value with no corresponding [[primary key]] value in the referenced table. What happened here was that there was an artist called "[[Aerosmith]]", with an <code>artist_id</code> of <code>4</code>, which was deleted from the artist table. However, the album "[[Eat the Rich (Aerosmith song)|Eat the Rich]]" referred to this artist. With referential integrity enforced, this would not have been possible.]] '''Referential integrity''' is a property of data stating that all its references are valid. In the context of [[relational database]]s, it requires that if a value of one attribute (column) of a [[relation (database)|relation]] (table) references a value of another attribute (either in the same or a different relation), then the referenced value must exist.<ref>{{cite web |last=Chapple |first=Mike |title=Referential Integrity |work=About.com Tech |publisher=About.com |url=http://databases.about.com/cs/administration/g/refintegrity.htm |access-date = 2011-03-20 |quote='''Definition''': Referential integrity is a database concept that ensures that relationships between tables remain consistent. When one table has a foreign key to another table, the concept of referential integrity states that you may not add a record to the table that contains the foreign key unless there is a corresponding record in the linked table.}}</ref> For referential integrity to hold in a relational database, any column in a base [[table (database)|table]] that is declared a [[foreign key]] can only contain either null values or values from a parent table's [[primary key]] or a [[candidate key]].<ref>Coronel et al. (2013). Database Systems 10th ed. Cengage Learning, {{ISBN|978-1-111-96960-8}}</ref> In other words, when 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 system]]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]]. The adjective 'referential' describes the action that a [[foreign key]] performs, 'referring' to a linked column in another table. In simple terms, 'referential integrity' guarantees that the target 'referred' to will be found. A lack of referential integrity in a database can lead relational databases to return incomplete data, usually with no indication of an error.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)