Difference b/w Composite & Candidate Keys




  • Composite Key

Sometimes there is no single attribute that can uniquely identify rows in a relation, In such situations, a combination of two or more attributes may be used as the primary key for the relation A primary key that is made up of more than one attribute is known as a composite key It is also called concatenated key

Each row of the relation WORK can be uniquely identified only by a composite key consisting of Emp-ID and Prj-ID. The composite key is identified by underlining all the attributes that make up the composite key

WORK(Emp-ID Pr-ID, H-Worked)

  • Candidate Key

Sometimes, a relation has more than one attribute or set of attributes that can be used as the primary key Any attribute or a set of attributes that can be used as a primary key is called a candidate key)

Although there can be more than one attribute that can be used as a primary key, only one is selected. Candidate keys that are not chosen as the primary key are referred to as alternate keys.

For example, consider the following relation:

EMPLOYEE(Emp-ID. Emp-IDCard, Emp-Name, Emp-DOB)

In this relation, the Emp-ID and Emp-ID Card for each employee will be unique. No two employees will have the same ID Card Numbers. These two attributes are the candidate keys of the relation. Therefore, either of these two can be used as the primary key of the relation. If Emp-ID is used as the primary key of the relation, then Emp-ID Card becomes the alternate key.


Post a Comment

0 Comments