We may not have the course you’re looking for. If you enquire or give us a call on +91-181-5047001 and speak to our training experts, we may still be able to help with your training requirements.

What This Guide Covers
1. The meaning and purpose of keys in DBMS.2. Different types of keys, including Primary, Foreign, Candidate and Super Keys.3. The role of Composite, Unique, Alternate and Surrogate Keys.4. Practical examples showing how different keys work in database tables.5. The importance of keys in maintaining relationships, uniqueness and data integrity.
In the realm of Database Management Systems (DBMS), keys play a crucial role in organising and accessing data efficiently. Understanding the various types of keys is essential for designing a robust and well-structured database. Common types of keys in DBMS include the Primary Key, Foreign Key, Candidate Key, Super Key, Alternate Key, Composite Key, Unique Key and Surrogate Key.
This blog will delve into the different types of keys in DBMS, their characteristics, and their significance in maintaining data integrity.
Definition of Keys in DBMS
In Database Management Systems (DBMS), keys play a crucial role in ensuring the efficient organisation and retrieval of data. A key is a field or set of fields used to identify records, enforce constraints or establish relationships between tables, depending on the type of key.
Keys also play an important role in database normalisation. For example, Candidate Keys and Super Keys are used when evaluating functional dependencies in normal forms such as BCNF.
Types of Keys
In Database Management Systems (DBMS), different types of keys are used to identify records, enforce data integrity and establish relationships between tables. Here are some key types commonly used in DBMS:

1) Primary Key
A Primary Key in Database Management Systems (DBMS) is a unique identifier for each record in a table, ensuring data integrity and facilitating relationships between tables. It uniquely distinguishes each row, making it a fundamental component of relational databases.
The Primary Key's defining characteristics include uniqueness and non-null values. Primary Key values should also generally remain stable to simplify database relationships and maintenance. Its role in maintaining data accuracy is pivotal, as the Primary Key helps prevent duplicate identifiers and establishes a reliable reference point for relationships within the database.
Example of a Primary Key
Suppose a Students table contains:

Here, Student_ID is the Primary Key because it uniquely identifies each student in the table. Each Student_ID value must be unique and cannot be NULL.
For example, two students cannot both have Student_ID = 101, as this would violate the Primary Key constraint. Similarly, a student record cannot have a NULL value for Student_ID.
Pro Tip
When choosing a Primary Key, prefer an identifier that is unique, simple and unlikely to change. Stable Primary Key values make relationships between tables easier to maintain and reduce complications when records are referenced elsewhere.
2) Unique Key
In a Database Management System (DBMS), a Unique Key usually refers to a column or set of columns on which a UNIQUE constraint is applied, ensuring that duplicate values are restricted according to the rules of the DBMS.
Unlike the Primary Key, a Unique Key does not necessarily serve as the primary means of identification for records but helps enforce data integrity by preventing duplicate values in specified columns.
Additionally, a table can have multiple unique keys, each defining a distinct uniqueness constraint. This feature is particularly useful when an alternate identifier, other than the primary key, needs to be unique across records, such as in the case of email addresses or passport numbers.
Remember
A table can have only one Primary Key constraint but can have multiple Unique constraints. Also, NULL handling under Unique constraints can vary between database systems, so always check the rules of the DBMS you are using.
3) Foreign Key
In a Database Management System (DBMS), a Foreign Key is a crucial relational database concept that establishes a connection between tables. It is a column or set of columns in one table that references a Primary Key, Unique Key or another eligible referenced key in a related table, depending on the DBMS.
The purpose of a Foreign Key is to enforce Referential Integrity, helping ensure that references between related data remain valid.
By using Foreign Keys, a table can reference eligible key values in a related table, establishing dependencies and meaningful connections between different sets of data.
Example of a Foreign Key
Consider two tables: Students and Enrolments.
Students Table
|
Student_ID
|
Student_Name
|
|
101
|
Alex
|
|
102
|
Priya
|
Enrolments Table
|
Enrolment_ID
|
Student_ID
|
Course
|
|
E01
|
101
|
Database Management
|
|
E02
|
102
|
Data Analytics
|
|
E03
|
101
|
SQL
|
Here, Student_ID in the Students table is the Primary Key, while Student_ID in the Enrolments table is a Foreign Key that references it. Notice that 101 appears more than once in the Enrolments table. This is valid because Foreign Key values do not need to be unique and multiple enrolments can belong to the same student.
4) Composite Key
In a Database Management System (DBMS), a Composite Key consists of two or more columns used together to uniquely identify a record. When the combination is minimal and uniquely identifies each record, it can be a Candidate Key. If selected as the table's Primary Key, it becomes a composite Primary Key.
This is particularly useful when a single attribute does not provide enough distinction between records. When a composite key is used to uniquely identify rows, the combination of its column values must be unique. While providing a robust means of uniquely identifying records, composite keys can make queries more complex.
Consider an Enrolments table where a student can enrol in several courses, but only once in each course.
Example of a Composite Key

Neither Student_ID nor Course_ID alone uniquely identifies an enrolment. However, the combination of Student_ID + Course_ID uniquely identifies each enrolment. Therefore, these two columns can form a Composite Key.
5) Super Key
In Database Management Systems (DBMS), a Super Key is a set of one or more attributes (columns) that, taken together, uniquely identifies a record within a table.
It represents a broader concept that includes Candidate Keys and Primary Keys. A Composite Key can also be a Super Key when its combined attributes uniquely identify each record.
The attributes chosen for a Super Key determine how records are uniquely identified. Any set of attributes that uniquely identifies a row qualifies as a Super Key, even if it contains unnecessary attributes. A Super Key may contain more attributes than necessary for uniqueness. A Super Key with no unnecessary attributes is known as a Candidate Key.
Learn about data normalisation, de-normalisation, and SQL queries with our Relational Databases & Data Modelling Training – Register now!
6) Candidate Key
A candidate key in a DBMS refers to a set of one or more attributes (columns) in a table that can uniquely identify each record. These keys are potential candidates for becoming the primary key of the table. To qualify as a candidate key, the set of attributes must be unique for each record, and no subset of these attributes should possess the same uniqueness property.
In essence, candidate keys are minimal super keys, ensuring that removing any attribute from the set would result in a loss of uniqueness. Database designers typically evaluate multiple candidate keys before selecting the primary key based on factors like simplicity, stability, and ease of use.
7) Alternate Key
An Alternate Key is a candidate key within a table that is not selected as the primary key. While candidate keys are potential choices for the primary identifier of a record, an alternate key represents an alternative option.
These keys exhibit the same uniqueness characteristics as the primary key and could function as the primary key if the chosen primary key were not available or practical. The selection of the primary key from among the candidate keys often involves considerations of simplicity, stability, and usability.
Trainer’s Insight
Super Keys, Candidate Keys, Primary Keys and Alternate Keys are closely related rather than completely separate concepts. A Candidate Key is a minimal Super Key. One Candidate Key is selected as the Primary Key, while the remaining Candidate Keys are considered Alternate Keys.
8) Surrogate Key
A Surrogate Key is an artificial or synthetic key introduced to serve as the primary identifier for records within a table. It is typically a system-generated value, such as an auto-incremented number, with no inherent business meaning. Surrogate Keys are commonly used as Primary Keys, although the surrogate value itself does not guarantee uniqueness unless an appropriate constraint is applied.
The primary purpose of a Surrogate Key is to provide a simple and stable identifier, particularly when a suitable natural key is absent or impractical to use.
Example of a Surrogate Key
Suppose a Customers table contains:

Here, Customer_ID is a Surrogate Key because it is a system-generated identifier with no inherent business meaning. It can be used as the Primary Key to uniquely identify each customer.
The Email column represents meaningful business data and may change over time, whereas Customer_ID can remain stable even when a customer's details change. A Unique constraint can still be applied to Email if every customer is required to have a distinct email address.
Importance of Keys in Database Management Systems
The importance of keys in Database Management Systems (DBMS) lies in their fundamental role in organising, structuring, and maintaining the integrity of data. Keys serve several crucial functions in database management:
a) Uniqueness and Identification: Keys, especially primary keys, ensure the uniqueness of each record in a table. This uniqueness is vital for accurately identifying and distinguishing one record from another, preventing duplication and ensuring data accuracy.
b) Relationships Between Tables: Foreign Keys establish relationships between tables by referencing eligible keys in related tables. These relationships help maintain referential integrity and consistency between related data.
c) Data Integrity: Key constraints support data integrity in different ways. Primary Key constraints enforce uniqueness and non-nullability, Unique constraints enforce uniqueness according to the DBMS's rules, and Foreign Key constraints help maintain referential integrity between related data.
d) Efficient Data Retrieval: Keys are often supported by indexes, which can improve the efficiency of lookups, joins and other data retrieval operations. However, keys and indexes are different concepts: keys define logical constraints and relationships, while indexes are data structures used to support efficient data access.
Keys are essential components of a DBMS that help uniquely identify records, establish relationships between tables and maintain data integrity. Understanding how different key types work and relate to each other can help you design more accurate, consistent and well-structured relational databases.
Gain essential skills through Introduction to Database training and build smart solutions with our Introduction to Database Training – Join now!
The Knowledge Academy develops accessible learning content across Project Management, IT, Cybersecurity, Data Science, Business Analysis, HR, Accounting and Finance, Leadership and Health and Safety. Its resources combine subject research with clear explanations to help professionals build practical knowledge across a wide range of disciplines.
View Detail