Keys in Relational Model (original) (raw)

Last Updated : 24 Apr, 2026

Keys are fundamental elements of the relational database model that ensure uniqueness, data integrity, and efficient data access.

different_kinds_of_keys

Keys in DBMS

Importance of Keys in DBMS

Types of Database Keys

1. Candidate Key

The minimal set of attributes that can uniquely identify a tuple is known as a candidate key. For Example, STUD_NO in STUDENT relation.

Example: For the STUDENT table below, STUD_NO can be a candidate key, as it uniquely identifies each record.

Screenshot-2026-01-13-155330

STUDENT Table

**Table: STUDENT_COURSE

Screenshot-2026-01-13-155747

STUDENT_COURSE Table

A composite candidate key example: {STUD_NO, COURSE_NO} can be a candidate key for a STUDENT_COURSE table.

2. Super Key

The set of one or more attributes (columns) that can uniquely identify a tuple (record) is known as Super Key. It may include extra attributes that aren't important for uniqueness but still uniquely identify the row. For Example, STUD_NO, (STUD_NO, STUD_NAME), etc.

**Example: Consider the STUDENT table

Screenshot-2026-01-13-155330

STUDENT Table

A super key could be a combination of STUD_NO and PHONE, as this combination uniquely identifies a student.

Relation between Primary Key, Candidate Key and Super Key

Relation between Primary Key, Candidate Key, and Super Key

3. Alternate Key

An alternate key is any candidate key in a table that is not chosen as the primary key. In other words, all the keys that are not selected as the primary key are considered alternate keys.

**Example: In the STUDENT table, both STUD_NO and PHONE are candidate keys. If STUD_NO is chosen as the primary key, then PHONE would be considered an alternate key.

Primary Key, Candidate Key and Alternate Key

Primary Key, Candidate Key, and Alternate Key

4. Foreign Key

A foreign key is an attribute in one table that refers to the primary key in another table. The table that contains the foreign key is called the referencing table and the table that is referenced is called the referenced table.

Foreign-keys

Relation between Primary Key and Foreign Key

Example: Consider the STUDENT_COURSE table

Screenshot-2026-01-13-155747

STUDENT_COURSE Table

5. Partial Key

A partial key is chosen from a weak entity to help identify records, but it cannot uniquely identify a record by itself.

Example: In a STUDENT_COURSE table, the combination of STUD_NO and COURSE_CODE can be a partial key.

Screenshot-2026-02-20-181108

6. Primary Key

A primary key is chosen from the set of candidate keys to uniquely identify each record in a table. For example, in the STUDENT table, both STUD_NO and STUD_PHONE can be candidate keys, but STUD_NO is selected as the primary key.

**Example: The STUDENT table has the structure Student(STUD_NO, SNAME, ADDRESS, PHONE), where STUD_NO is the primary key.

Screenshot-2026-01-13-155330

7. Secondary Key

A Secondary Key is an attribute or a combination of attributes used to search or query records in a table, but it doesn’t guarantee uniqueness.

Here's an example of how the STUDENT table might look with STUD_NAME as a secondary key:

STUD_NO STUD_NAME STUD_AGE STUD_ADDRESS
101 John 21 123 Oak St
102 Emily 22 456 Pine St
103 John 23 789 Maple St
104 Michael 20 321 Birch St
105 Emily 22 654 Cedar St

8. Unique Key

A Unique Key is a database constraint that ensures that all values in a specific column or a combination of columns are unique across all the rows in a table. It guarantees that no two rows in the table can have the same value in the columns defined as part of the unique key.

**Example: In the STUDENT_COURSE table, the combination of STUD_EMAIL and STUD_NAME can form a Unique Key to ensure that each student’s email and name pair is unique across the table.

STUD_NO STUD_EMAIL STUD_NAME
101 john@example.com John
102 emily@example.com Emily
103 michael@example.com Michael
104 sara@example.com Sara
105 david@example.com David

9. Composite Key

Sometimes, a single column is not enough to uniquely identify all records in a table, so a combination of multiple attributes is used. An optimal set of such attributes is chosen to ensure that every row is uniquely identifiable.

It acts as a primary key if there is no primary key in a table

**Example: In the STUDENT_COURSE table, {STUD_NO, COURSE_NO} can form a composite key to uniquely identify each record.

Different Types of Keys

10. Surrogate Keys

A surrogate key is an artificial attribute created to uniquely identify each record in a table when no suitable natural key is available.

**Example: STUDENT_ID is used as a surrogate key to uniquely identify each record in the STUDENT_COURSE table, without relying on natural attributes like name or email.

Screenshot-2026-02-21-164200