May 4th, 2009

How do Constraints Work?, FOREIGN KEY (Part 1 of 5)

Posted by admin in P. Table Creation

Foreign keys were discussed in Relational Database Basics. Let us review:Foreign keys are used to associate data between tables. For instance, a foreign key of REP in the CUSTOMER_TBL points to the primary key EMPL_ID in the EMPLOYEE_TBL.

> A foreign key is one or more columns in a table whose values reference values in another table.

> A foreign key in the child table establishes a relationship to the primary key in the parent table.

> The matching foreign key and primary key can have different names.

> If the relationship is enforced, then this is called referential integrity.

> If the relationship is not enforced and there is a foreign key in a child table that does not match the primary key of the parent table, then this is called an orphan row.

> Unlike primary keys, foreign keys can be empty with a null.

> Foreign keys are not always unique in their table.

> A foreign key can reference the primary key of the same table. For instance, the MANAGER of an employee can reference the EMPLOYEE ID for the manager.

 

Comments are closed.

Sorry, the comment form is closed at this time.