What Are The Types of Keys in DBMS? Examples, Usage, and Benefits
By Rohan Vats
Updated on Dec 06, 2025 | 20 min read | 343.48K+ views
Share:
Working professionals
Fresh graduates
More
By Rohan Vats
Updated on Dec 06, 2025 | 20 min read | 343.48K+ views
Share:
Table of Contents
Latest Update: With its latest update, IBM Db2 12.1.2 now supports vectorized data—making it AI-ready for tasks like recommendation systems and RAG models. Smarter searches, faster results—all in one powerful DBMS! |
How many types of keys in DBMS are there? If you are not aware of the answer to this query, don't fret! You are at the right place. Before diving deep, it’s important to understand what is key in DBMS, a key is an attribute or a set of attributes that helps uniquely identify records in a table. In a DBMS, there are eight main types of keys: super key, primary key, candidate key, alternate key, foreign key, composite key, unique key, and surrogate key.
You might wonder why they hold so much importance. Different types of Keys prevent confusion when you deal with large datasets. They also define how different tables should connect, which supports more efficient searches.
This article will walk you through the different types of keys in a DBMS. By the end, you will understand how each key type fits into the bigger picture of reliable database design.
Transform Your Career with Data Science.
Master analytics through expert-led Data Science Course and shape the future with data.
Explore Programs That Fit You!
Relational databases, also known as SQL databases, rely on different key types to keep each record distinct and to connect data across multiple tables. Each type handles its own task, such as avoiding duplicates or linking related tables.
Take the Leap into Data Science and AI.
Learn from top institutions like IIIT-B and Liverpool John Moores University and become a leader in tomorrow’s data-driven world.
Below is a quick view of eight fundamental types of keys in DBMS and what they do.
Keys in DBMS |
Description |
| Super Key | One or more columns that can single out every row, even if they include extra attributes not strictly needed for uniqueness. |
| Primary Key | The minimal set of attributes needed to identify a row without any duplicates or null values. |
| Candidate Key | Any key that qualifies to become a primary key because it’s both unique and minimal. |
| Alternate Key | A candidate key not used as the primary key. It still uniquely identifies rows, but it isn’t the main choice for the table. |
| Foreign Key | A column in one table that matches a primary key in another table to keep their data aligned. |
| Composite Key | Two or more columns combined to form a unique identifier. Helpful when no single column can do the job on its own. |
| Unique Key | Demands that all values differ within a column (or set of columns), though it typically allows one null. It prevents repeated entries. |
| Surrogate Key | A system-generated key with no direct real-world meaning, often auto-incremented or assigned by the database itself. |
Now that you know the main keys in SQL, let’s explore them in detail.
A super key in DBMS is a collection of one or more columns that can identify every row in a table without confusion. It may include extra columns that are not strictly necessary for uniqueness, but any row that matches all the columns in the super key is guaranteed to be one of a kind.
This differs from a candidate key, which is also unique but contains no redundant attributes.
Let’s understand this with an example:
Below is a sample table that stores basic student information:
StudentID |
StudentName |
ContactNumber |
|
| 1 | Arun | 98765XXXXX | arun@example.com |
| 2 | Meera | 99887XXXXX | meera@example.com |
| 3 | Kirti | 98767XXXXX | kirti@example.com |
Software Development Courses to upskill
Explore Software Development Courses for Career Progression
A primary key in DBMS is the minimal set of columns that pinpoint a row in a table. It does not allow duplicates or empty values, which makes it the firmest boundary, preventing confusion between records. This key is the preferred choice for queries that count on accurate and immediate results.
Let’s understand this with an example:
Below is a sample table for your reference:
BookID |
Title |
Author |
Price |
| 101 | A Tale of Two Cities | Charles Dickens | INR 300 |
| 102 | Pride and Prejudice | Jane Austen | INR 280 |
| 103 | The Great Gatsby | F. Scott Fitzgerald | INR 350 |
Did you know? Any column already unique enough to be a primary key automatically qualifies as a super key. However, the reverse might not always be true because a super key can hold extra columns that aren’t strictly needed for identifying a row.
A candidate key is a minimal group of columns that guarantee a row’s uniqueness in a table. Unlike a super key, which can hold extra columns that aren’t required for uniqueness, a candidate key includes only what’s strictly necessary.
You may find several candidate keys in a single table, but each one meets the same standard: no duplicates and no extra fields that could be removed without losing uniqueness.
Let’s understand this with an example:
Below is a sample table that highlights these columns:
FlightID |
FlightNumber |
DepartureTime |
ArrivalTime |
GateNumber |
| 1 | AI-203 | 8:30 AM | 10:45 AM | B5 |
| 2 | AI-204 | 9:00 PM | 11:15 PM | B7 |
| 3 | AI-205 | 10:00 AM | 12:20 AM | C1 |
Also Read: Attributes in DBMS: 10 Types and Their Practical Role in Database Design
An alternate key is any candidate key that did not become the primary key. It still uniquely identifies a row in a table but isn’t chosen as the main identifier. That means a table can have multiple candidate keys (like Email and PhoneNumber), but only one of them serves as the primary key. The remaining candidate keys are known as alternate keys.
Let’s understand this with an example:
Below is a sample table where PatientID is primary, and you can treat HealthCardID or PhoneNumber as alternate keys.
PatientID |
PatientName |
PhoneNumber |
HealthCardID |
| 1 | Rakesh | 98765XXXXX | HCI-654321 |
| 2 | Kavya | 99000XXXXX | HCI-987654 |
| 3 | Rohit | 98877XXXXX | HCI-112233 |
Subscribe to upGrad's Newsletter
Join thousands of learners who receive useful tips
A foreign key is a column in one table that points to a primary key in another table. Its main purpose is to link two tables so that they share information in a consistent way. When you reference a foreign key, you ensure that the data in both tables stays synchronized, and entries only appear if there’s a valid match in the primary key column.
Let’s understand this with an example:
Below is a table that references a foreign key from the ‘Customers table’:
OrderID |
CustomerID |
ProductName |
OrderDate |
| 5001 | 101 | Wireless Mouse | 2025-01-12 |
| 5002 | 102 | Keyboard | 2025-01-13 |
| 5003 | 101 | Laptop Stand | 2025-01-14 |
You can also check out upGrad’s free tutorial, Difference Between Primary Key and Foreign Key.
A composite key is a combination of two or more columns that together make each row in a table unique. None of those columns alone can serve as the complete identifier, but merging them guarantees one-of-a-kind rows.
Composite keys often appear in many-to-many relationships, where individual columns can repeat themselves, but their pairing remains distinct.
Let’s understand this with an example:
Below is a sample table to highlight how two columns can work together:
StudentID |
CourseID |
EnrollmentDate |
| 101 | C001 | 2025-02-08 |
| 101 | C002 | 2025-02-09 |
| 102 | C001 | 2025-02-10 |
A unique key is a constraint that ensures no two rows in a table share the same value for a specified column. It functions similarly to a primary key but can allow a null value. You can mark a column or group of columns as unique if you need each record to stand out without necessarily making it the primary identifier of your table.
Let’s understand this with an example:
Below is a table showing unique values in the Email column:
MemberID |
PhoneNumber |
|
| 201 | user1@example.com | 98765XXXXX |
| 202 | user2@example.com | 99000XXXXX |
| 203 | (null) | 98767XXXXX |
A surrogate key is a system-generated column that identifies each row in a table but has no direct connection to real-world data. Many databases assign an automatically incrementing number as the surrogate key, and this approach offers a stable way to keep records distinct. It won't change over time and doesn't depend on user-provided values or business rules.
Let’s understand this with an example:
Below is a sample table, marking UserID as the surrogate key:
UserID |
Username |
JoinDate |
|
| 1 | coder123 | coder123@example.com | 2025-01-09 |
| 2 | devPro | devPro@example.com | 2025-01-10 |
| 3 | designGeek | designGeek@example.com | 2025-01-11 |
Want to refresh your basics regarding data structures? Join upGrad's free Certificate Course on Data Structures & Algorithms and get your revision done in a structured way!
upGrad’s Exclusive Software and Tech Webinar for you –
SAAS Business – What is So Different?
Data in a DBMS can turn disorganized if every record looks alike or repeats. You might have tried tracking one person’s details among hundreds of rows, only to discover entries that seem identical. DBMS Keys prevent that confusion and help you draw clear boundaries between records.
Here are some main reasons they matter:
Also Read: DBMS Tutorial For Beginners: Everything You Need To Know
Primary keys and unique keys both keep duplicate data out of your table. They do so in slightly different ways, especially when you consider their rules on null values and how they fit into the bigger design. Understanding these differences can make your database structure more efficient and flexible.
Take a look at the table below to see how each key type stands apart:
Aspect |
Primary Key |
Unique Key |
| Definition | Identifies rows by disallowing duplicates and nulls. | Demands distinct values in a column but can allow one null (depending on the database system). |
| Number Allowed | Only one per table | You can create multiple unique keys in the same table. |
| Handling Nulls | Never permits null values | Typically allows one null, but disallows duplicates among non-null entries. |
| Role | Serves as the main reference for relationships in other tables. | Provides an extra layer of uniqueness without being the table’s primary reference. |
| Enforcement Method | Declared with the PRIMARY KEY constraint | Enforced via the UNIQUE constraint |
| Indexing Behavior | Automatically indexed by most database systems for quick lookups. | Generally indexed, but implementation may vary by system. |
| Impact on Table Design | Central for a table’s identity; no two rows can share the same primary key. | Improves data quality by blocking accidental repeats, while still offering some flexibility through a null field if allowed. |
To build in-depth knowledge, you can also check out upGrad's free tutorial, Primary Key vs Unique Key.
Keys in SQL relational databases go beyond simply ensuring no two rows look alike. They also help you maintain order, handle large volumes of data, and preserve vital relationships between tables. Each key must meet specific standards so that your database doesn’t run into conflicts or inconsistencies.
Here are the main properties you should keep in mind:
There is a definite advantage in defining more than one type of key. Each one focuses on a particular data issue, such as removing duplication or linking related records in separate tables. This arrangement keeps a database flexible and well-prepared to handle both routine data and complex scenarios.
Here are some additional benefits you gain by using these different key types:
upGrad offers industry-relevant courses designed in partnership with leading universities and industry experts. With flexible learning, mentorship, and hands-on projects, upGrad helps you gain practical skills and stay ahead in fields like DBMS.
You can start with the following courses:
So, if you're ready to enhance your DBMS skills, take the first step towards your dream career—book a free career counseling session today for tailored expert advice. You can also visit your nearest upGrad offline career center and start shaping your future now!
Related Blogs:
Boost your career with our popular Software Engineering courses, offering hands-on training and expert guidance to turn you into a skilled software developer.
Master in-demand Software Development skills like coding, system design, DevOps, and agile methodologies to excel in today’s competitive tech industry.
Stay informed with our widely-read Software Development articles, covering everything from coding techniques to the latest advancements in software engineering.
A key in DBMS is an attribute or group of attributes that uniquely identifies each record in a table. Keys prevent duplication and maintain data accuracy. They also help define relationships between tables.
A super key is any combination of attributes that can uniquely identify a record. It may contain extra fields not required for uniqueness. All keys fall under super keys, but not all super keys are minimal.
A primary key is the main unique identifier for records in a table. It cannot have NULL values and must always remain unique. It ensures efficient record access and relational mapping.
A candidate key is a minimal attribute set that uniquely identifies a record. A table can have multiple candidate keys, but only one becomes the primary key. All candidate keys are free from redundant attributes.
An alternate key is any candidate key that is not selected as the primary key. It still uniquely identifies records when queried. It provides additional flexibility in data retrieval.
A foreign key links one table to another by referencing a primary key. It enforces referential integrity, ensuring child-table entries must match parent-table data. This maintains structured relationships in databases.
A composite key uses two or more attributes to uniquely identify records. It is helpful when no single field can act as a unique identifier. Often used in junction or mapping tables.
A unique key ensures no two rows have the same value in the specified column. Unlike a primary key, it allows one NULL value. It maintains uniqueness without strict non-NULL constraints.
A surrogate key is a system-generated identifier with no business meaning. It is often numeric and improves indexing and joins. Useful in large datasets and data warehousing.
A primary key must be unique and non-null, while a unique key allows one NULL value. Only one primary key exists per table, but multiple unique keys can be defined. Both enforce uniqueness but serve different constraints.
DBMS includes primary, composite, foreign, unique, surrogate, alternate, super, and candidate keys. Each plays a role in identification, relationships, and data validation. Understanding them helps design efficient relational models.
Key constraints ensure data validity and uniqueness, such as primary key, unique, and foreign key constraints. They prevent duplicates and enforce valid relationships. These rules maintain overall database integrity.
The concept refers to using attributes to identify, organize, and link data across tables. Keys prevent ambiguity and ensure accurate queries. They create the backbone of relational database structure.
Key attributes are fields that participate in uniquely identifying table records. They help form different types of keys like primary, candidate, or composite keys. Their role is crucial for indexing and retrieval.
Keys uniquely identify records—like StudentID in a student table. They support indexing, prevent duplicates, and maintain relationships. Examples include primary key, foreign key, and composite key.
A composite key uses multiple attributes for unique identification. For example, (OrderID, ProductID) in an OrderDetails table uniquely identifies each item. It is ideal when single-column uniqueness isn’t possible.
A candidate key is a minimal and unique attribute set capable of identifying records. It contains no unnecessary fields. One candidate key becomes the primary key.
A foreign key references another table’s primary key—e.g., CustomerID in Orders linking to Customers. It enforces valid relationships and prevents orphan records. Essential for relational consistency.
A super key is any attribute combination that uniquely identifies records, e.g., (Email, Phone) together. It may include additional fields beyond what’s required. Super keys help identify candidate keys.
DBMS uses primary, composite, candidate, alternate, foreign, unique, surrogate, and super keys. Each ensures accurate identification, efficient search, and strong relational mapping. They collectively support data integrity.
417 articles published
Rohan Vats is a Senior Engineering Manager with over a decade of experience in building scalable frontend architectures and leading high-performing engineering teams. Holding a B.Tech in Computer Scie...
Get Free Consultation
By submitting, I accept the T&C and
Privacy Policy
India’s #1 Tech University
Executive PG Certification in AI-Powered Full Stack Development
77%
seats filled
Top Resources