Tuesday, April 17, 2012

foreign key

foreign key - a foreign key is one which will refer to a primary key of another table
http://www.allinterview.com/showanswers/15625.html

A foreign key is a relationship or link between two tables which ensures that the data stored in a database is consistent.
The foreign key link is set up by matching columns in one table (the child) to the primary key columns in another table (the parent)
http://www.visualcase.com/kbase/database_basics_-_foreign_keys.htm


Foreign Key:
A foreign key (sometimes called a referencing key) is a key used to link two tables together.
Typically you take the primary key field from one table and insert it into the other table where it becomes a foreign key
(it remains a primary key in the original table).

A foreign key constraint specifies that the data in a foreign key must match the data in the primary key of the linked table, in the above example we couldn't set the DeptID in the Employee table to 04 as there is no DeptID of 04 in the Department table. This system is called referential integrity, it is to ensure that the data entered is correct and not orphaned (i.e. there are no broken links between data in the tables)
http://www.databasedev.co.uk/primary_foreign_key_constraints.html

No comments:

Post a Comment