SQL Keys are important in relational database. A key can be defined as a single or combination of multiple columns in a table. SQL Keys are also used to create relationship between multiple tables. So, in this post we will discuss about the concept and types of keys used in SQL Server.

There are different types of keys in SQL Server which are follows:-

Primary Key

Primary key is used to uniquely identify the records in a SQL Table. Here we can say, primary key is a value of a column that value is unique in the table. Primary key don't accept any null value. Primary Key is also play an important role to create relationship between two tables. Click here to know more details about Primary Key

Unique Key

Unique key is also used to uniquely identify the records in a SQL Table. The main difference between Unique Key and Primary Key is unique key accept one NULL value but primary key don't.

Foreign Key

Foreign is a reference key of Primary Key that is used to make a relationship between two tables.

Composite/Compound Key

Composite Key can be defined as a combination of more than one columns to uniquely identify the records in a table. Columns which can be combine to make a composite key can be a Candidate Key and Primary Key.

Alternate Key

Alternate Key can be defined as a key that can be work as a primary key if required. We can understand alternate key as a candidate for primary key as candidate key but its not a primary key.

Candidate Key

Candidate Key can be defined as a set of one or more columns that can identify a record uniquely in a table like a primary key.