Beginner’s Guide
Different
Types of Keys
in Databases
and Their
Uses
Pradeep M
@pradeep-m-analyst
1
Primary Key
It’s like a unique ID for each row in a table.
It ensures that each row is unique and
cannot be null.
2
Foreign Key
A foreign key links a table to another table
by referencing its primary key, creating
relationships.
Example: An "Orders" table might connect
to "Customers" using a foreign key
referencing the "Customer ID."
3
Composite Key
When a single column isn't enough to
uniquely identify a record, we combine
two or more columns.
Example: An "Invoice" table might use
"Invoice Number" and "Invoice Date"
together to uniquely identify each invoice.
4
Super Key
Any group of columns in a super key can
uniquely identify a record, but only one
becomes the primary key.
Example: A "Student" table might have
"Student ID," "Last Name," and "First
Name" as a super key, but only "Student
ID" might be chosen.
5
Candidate Key
Like a contender for primary key, a
candidate key is unique but might not be
the chosen one.
Example: In the "Student" table, both
"Student ID" and "Email" (if unique) could
be candidate keys.
6
Unique Key
Similar to a primary key, a unique key
ensures no duplicates, but allows one
record to be missing a value.
Example: A "Product" table might have a
unique key on "Product Code" to allow for
a product without a code yet.
7
Alternate Key
This is a backup option for unique
identification within a table, offering
flexibility.
Example: A "User" table might have a
primary key on "User ID" and an alternate
key on "Email" for login purposes.
8
Natural Key
This is a key that naturally identifies a row.
Example: An email address
9
Surrogate Key
When there's no natural unique identifier,
we create an artificial key.
Example: An "Employee" table might use
an auto-generated "Employee ID" as a
surrogate key.
10
Secondary Key
These don't identify records directly, but
act like helpful indexes to speed up
searches.
Example: A "Products" table might have a
secondary key on "Category" for faster
searches by category.
Did you find this
valuable?
Show some love with a like and inspire
me to create more!
Pradeep M
@pradeep-m-analyst