Data Modeling - Foreign Key Constraint

1 - About

A Foreign Key (also known as as a foreign key constraint) is:

  • a column
  • or combination of columns

used to establish and enforce a relationship between data in two tables.

Usually the foreign key is coupled with the primary key of the other table.

3 - Example

An Foreign Key example of a database (with the scott schema from Oracle).

Consider a part of the EMP (Employe) table.

EMPNO ENAME DPTNO
7369 SMITH 10
7499 ALLEN 20
7566 JONES 30

The column DPTNO from the EMP table refer to the column DEPTNO from the table DEPT (Department) below :

DEPTNO DNAME
10 ACCOUNTING
20 RESEARCH
30 DISTRIBUTION

For each DPTNO in the table EMP, you must have a DPTNO in the table DEPT. We say then that :

  • the column DPTNO from the table EMP is a foreign key.
  • and then that the column DEPTNO is a primary key.

If it's not true, there is NO referential integrity.

  • Bookmark "Data Modeling - Foreign Key Constraint" at del.icio.us
  • Bookmark "Data Modeling - Foreign Key Constraint" at Digg
  • Bookmark "Data Modeling - Foreign Key Constraint" at Ask
  • Bookmark "Data Modeling - Foreign Key Constraint" at Google
  • Bookmark "Data Modeling - Foreign Key Constraint" at StumbleUpon
  • Bookmark "Data Modeling - Foreign Key Constraint" at Technorati
  • Bookmark "Data Modeling - Foreign Key Constraint" at Live Bookmarks
  • Bookmark "Data Modeling - Foreign Key Constraint" at Yahoo! Myweb
  • Bookmark "Data Modeling - Foreign Key Constraint" at Facebook
  • Bookmark "Data Modeling - Foreign Key Constraint" at Yahoo! Bookmarks
  • Bookmark "Data Modeling - Foreign Key Constraint" at Twitter
  • Bookmark "Data Modeling - Foreign Key Constraint" at myAOL
data_modeling/foreign_key.txt ยท Last modified: 2012/04/03 14:04 by gerardnico