Illustrate the difference between primary key and foreign key.
Database Management System > Keys in DDMS > Foreign key
2360
Answer:
A candidate key that is chosen to uniquely identify a tuple in a relation is known as primary key (PK). Other candidate keys that are not chosen as primary key are known as alternate keys. The attribute whose value is never or rarely changed should be chosen as primary key. For example, in PUBLISHER
relation (shown in Figure below), the attribute Address
should not be chosen as a primary key since it can be changed often. However, the attribute P_ID
can be chosen as a primary key since each publisher has a unique publisher id and generally, it does not change.
Attribute of one relation can be accessed in another relation by enforcing a link between the attributes of two relations. This can be done by defining the attribute of one relation as the foreign key that refers to the primary key of another relation. For example, consider two relations, namely, PUBLISHER
and BOOK.
Here, all the books must be associated with a publisher that is already in the PUBLISHER
relation. In this case, a foreign key will be defined on the BOOK
relation, which will be related to the primary key of the PUBLISHER
relation. Thus, all books in the BOOK
relation would be related to a publisher in the PUBLI SHER
relation. A relation that references another relation is known as referencing relation whereas a relation that is being referenced is known as referenced relation. Figure below shows that the attribute P_ID
is a primary key in PUBLISHER
relation whereas it is a foreign key in BOOK
relation.
This Particular section is dedicated to Question & Answer only. If you want learn more about Database Management System. Then you can visit below links to get more depth on this subject.
Join Our telegram group to ask Questions
Click below button to join our groups.