Types of Keys in SQL
Types of Keys in SQL
Types of keys
in SQL
SWIPE
02/09
1. Super Key
A super key is any set of columns in a table that can uniquely
identify each row. Even if one column alone is enough to make
each row unique, adding extra columns still forms a super key, as
long as the combination ensures no two rows are identical in
those columns.
KEEP SWIPING
03/09
2. Candidate Key
A Candidate key is a minimal super key, which means it contains
no extra attributes that are not needed for uniqueness. In simpler
terms, it is the smallest combination of columns that can
uniquely identify a row in a table.
ONE MORE
04/09
3. Primary Key
A Primary key is a special type of candidate key chosen to
uniquely identify each row in a table. There can be only one
primary key in a table and it must be unique and cannot contain
null values.
ONE MORE
05/09
4. Alternate Key
An alternate key is a candidate key that is not used as the
primary key. While the primary key is the main way to uniquely
identify each row, alternate keys serve as additional unique
identifiers.
ONE MORE
06/09
5. Composite Key
A composite key is a type of candidate key or primary key that
consists of two or more attributes. When no single attribute can
uniquely identify a record in a table, we can use a combination of
attributes to achieve uniqueness. This grouping of attributes
ensures that each row in the table can be uniquely identified.
ONE MORE
07/09
6. Foreign Key
A foreign key is a primary key from one table that is used to
establish a relationship with another table.
ONE MORE
08/09
7. Surrogate Key
A surrogate key is a unique identifier for a record in a database
that is not based on the actual data in the record. Instead of
using a meaningful piece of information like an email address or
a name, a surrogate key is typically a simple number or code that
is automatically generated.
ONE MORE
09/09
COMMENT BELOW