Foreign_key - Foreign key From Wikipedia the free...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Foreign key From Wikipedia, the free encyclopedia Jump to: navigation , search This article may be too technical for most readers to understand . Please help improve this article to make it understandable to non-experts , without removing the technical details. The talk page may contain suggestions. (December 2010) In the context of relational databases , a foreign key is a referential constraint between two tables . [1] A foreign key is a field in a relational table that matches a candidate key of another table. The foreign key can be used to cross-reference tables. The foreign key identifies a column or set of columns in one (referencing) table that refers to a column or set of columns in another (referenced) table. The columns in the referencing table must reference the columns of the primary key or other superkey in the referenced table. The values in one row of the referencing columns must occur in a single row in the referenced table. Thus, a row in the referencing table cannot contain values that don't exist in the referenced table (except potentially NULL). This way references can be made to link information together and it is an essential part of database normalization . Multiple rows in the referencing table may refer to the same row in the referenced table. Most of the time, it reflects the one (parent table or referenced table) to many (child table, or referencing table) relationship. The referencing and referenced table may be the same table, i.e. the foreign key refers back to the same table. Such a foreign key is known in SQL:2003 as a self-referencing or recursive foreign key. A table may have multiple foreign keys, and each foreign key can have a different referenced table. Each foreign key is enforced independently by the database system . Therefore, cascading relationships between tables can be established using foreign keys. Improper foreign key/primary key relationships or not enforcing those relationships are often the source of many database and data modeling problems.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Contents 1 Definin g Foreign Keys 2 Referen tial Actions 2 . 1 C A S C A D E 2 . 2 R E S T R I C T 2 . 3 N O A C T I O N 2 .
Background image of page 2
[ edit ] Defining Foreign Keys Foreign keys are defined in the ANSI SQL Standard, through a FOREIGN KEY constraint. The syntax to add such a constraint to an existing table is defined in SQL:2003 as shown below. Omitting the column list in the REFERENCES clause implies that the foreign key shall reference the primary key of the referenced table. ALTER TABLE <TABLE identifier> ADD [ CONSTRAINT <CONSTRAINT identifier> ] FOREIGN KEY ( <COLUMN expression> {, <COLUMN expression>}. .. ) REFERENCES <TABLE identifier> [ ( <COLUMN expression> {, <COLUMN expression>}. .. ) ] [ ON UPDATE <referential action> ] [ ON DELETE <referential action> ] Likewise, foreign keys can be defined as part of the CREATE TABLE SQL statement. CREATE TABLE TABLE_NAME (
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/30/2011 for the course MIS 325 taught by Professor Mote during the Spring '08 term at University of Texas.

Page1 / 12

Foreign_key - Foreign key From Wikipedia the free...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online