CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon


Question

Define foreign key. How is this concept useful in relational data model? Illustrate with suitable example.


Solution

A foreign key is a column or group of columns in a relational database table that provides a link between data in two tables. It acts as a cross-reference between tables because it references the primary key of another table, thereby establishing a link between them.
While key and entity constraints are specified on individual relation, the referential integrity constraint is specified between two or more relations. This constraint is specified to maintain consistency among the tuples of such relations. Accordingly, a tuple in one relation that refers to another relation must refer to an existing tuple in that other relation.

In referencing Accounts Type, Accounts relation uses its attribute. Type, which acts as foreign key to reference the tuples of relation Accounts Type through its primary key CatId. The value of Type cannot be null because of total participation of Accounts in classify relationship.

Say e.g., there are two tables EMP (EMPNO, ENM, SAL, DPTNO(Foreign Key))

DEPT (DPTNO {Primary Key}, DNM, LOC)

The foreign key DPTNO of EMP Table takes its value as a reference from DEPT TABLE DPTNO.

flag
 Suggest corrections
thumbs-up
 
0 Upvotes


Similar questions
View More


People also searched for
View More



footer-image