Keys play an important role in SQL. They are fields in a table that identify specific rows and are used to create relationships between tables. They can also help to quickly retrieve data.
There are various types of keys:
Primary key – It is an attribute that cannot be null and uniquely defines a row. Types of primary keys:
- Surrogate key – has no mapping to the real world
- Natural key – has a mapping/ purpose to the real world and not just in the database (ex. SSN can be a primary key that serves as a unique identifier and also has a purpose in the real world)
Foreign key – It stores the primary key of a row in another database table.
Composite key – It is a combination of columns that uniquely identifies a row, so it is made up of 2 attributes to serve as a primary key.

