Data
Advertisements
Technology Guides
| |
A foreign key is a field or set of fields that are used to establish relationships between rows in a database. Example (1)A Customer table contains a row for each customer. Each customer row has a foreign key called ADDRESS_ID that points to the customer's Address.
Example (2)A Star table contains a row for each known star. Each star row has a foreign key called GALAXY_ID that points to the star's Galaxy.Example (3)An Actor table contains a row for each actor in a movie database. Each actor row has a foreign key called FAVORITE_ACTOR that points to the id of the Actor's favorite Actor.Technical OverviewA foreign key is a type of constraint that can be defined for a database. When defined, it helps the database to enforce referential integrity between tables. A foreign key must be defined as a primary key in the parent table. A table can contain a foreign key to itself. A foreign key must exist in the parent table or be null.
Parent & ChildA table with a foreign key is often referred to as a child with the related table being called a parent. The parent/child terminology is a little misleading as the relationship between tables isn't necessarily a hierarchy. Recursive Foreign KeyA foreign key in a table that refers to itself is known as a recursive foreign key. |
Type | Databases | Definition (1) | A field or set of fields that are used to establish relationships between rows in a database. | Definition (2) | A constraint that indicates a column or set of columns in a table is a reference to the primary key of another table or a self-reference to the table's own primary key. | Value | Establishing relationships between data entities.Enforcing referential integrity in a database. | Applies to | SQLRelational Databases | Related Concepts | Foreign KeyDatabasesData |
Data
This is the complete list of articles we have written about data.
If you enjoyed this page, please consider bookmarking Simplicable.
© 2010-2023 Simplicable. All Rights Reserved. Reproduction of materials found on this site, in any form, without explicit permission is prohibited.
View credits & copyrights or citation information for this page.
|