What is a foreign key, and what are the actual rules for a foreign key?
This is one of the key concepts in relational databases. Foreign keys are what allow the database designer to express the relationships between rows.
Every table in a database should have a declared "primary key". The primary key is a column or group of columns that will uniquely identify a row within a table. One of the easiest (and most efficient) ways to do this is to create an automatically incrementing numeric column that serves no purpose other than to identify the row.
A "foreign key" is a copy of a primary key of a "parent' row that is stored within the "child" row. For example, consider a time and billing system. Each row of WIP (Work In Progress) can belong on a bill, so the wip row should include a BillId column that can be NULL. When the row is inserted into the table, the BillId is NULL. Once the wip has been billed, the BillId of the related bill is put into the wip's BillId column, showing that this row of wip "belongs" to that bill.
For More Information
- What do you think about this answer? E-mail us at editor@searchDatabase.com with your feedback.
- The Best Database Design Web Links: tips, tutorials, scripts, and more.
- Have a Database Design tip to offer your fellow DBA's and developers? The best tips submitted will receive a cool prize--submit your tip today!
- Ask your technical Database Design questions--or help out your peers by answering them--in our live discussion forums.
- Ask the Experts yourself: Our Database Design guru is waiting to answer your toughest questions.
Dig Deeper on Oracle database design and architecture
Related Q&A from Pat Phelan
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.