Home / Questions / Differentiate between a superkey, a candidate key and a primary key.
Explanatory Question

Differentiate between a superkey, a candidate key and a primary key.

👁 1,364 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

A set of one or more attributes, when taken together, helps in uniquely identifying each entity is called a superkey. For example, the attribute P_ID of the entity type PUBLISHER can be used to uniquely identify each entity instance. Thus, P_ID is a superkey. The combination of the attributes P_ID and Name is also a superkey. One can also use the set of all attributes (P_ID, Name, Address, Phone, Email_ID) to uniquely identify each entity instance of the type PUBLISHER. Thus, the combination of all attributes is also a superkey.

However, P_ID itself can uniquely identify each entity instance, thus, other attributes are not required. Such a minimal superkey that does not contain any superfluous (extra) attribute in it is called a candidate key. A candidate key contains a minimized set of attributes that can be used to uniquely identify a single entity instance. For example, the attributes P_ID and Name are the candidate keys. However, the combination of P_ID and Name is not a candidate key. The candidate key, which is chosen by the database designer to uniquely identify entities, is known as the primary key. For example, the attribute P_ID can be chosen as the primary key. If a primary key is formed by the combination of two or more attributes, it is known as a composite key. A composite key must be minimal, that is, all the attributes that form the composite key must be included in the key attribute to uniquely identify the entities.