---
title: "What are key in SQL Server? How many types of keys in SQL Server and also define with example?"  
description: "What are key in SQL Server? How many types of keys in SQL Server and also define with example?"  
author: "Ethan Karla"  
published: 2021-09-14  
canonical: https://answers.mindstick.com/qa/93944/what-are-key-in-sql-server-how-many-types-of-keys-in-sql-server-and-also-define-with-example  
category: "database"  
tags: ["database", "database management system"]  
reading_time: 2 minutes  

---

# What are key in SQL Server? How many types of keys in SQL Server and also define with example?

What are the [keys](https://www.mindstick.com/blog/213/keys-in-database) to [SQL Server](https://www.mindstick.com/articles/12343/sql-server-2017-ctp-2-0-now-available)? How many types of keys are in SQL Server and also [define](https://answers.mindstick.com/qa/72286/for-define-what-rats-and-rabbits-use-their-claws) for example?

## Answers

### Answer by Ashutosh Kumar Verma

**Keys in [SQL](https://www.mindstick.com/articles/202/the-detailed-concept-of-stored-procedure-in-sql-server) [Server](https://www.mindstick.com/articles/710/apache-server-installation-on-windows) :**

A key is a single or combination of multiple columns in database tables. Keys are used to retrieve data and rows from Database table based on requirement or conditions. Keys are also used to create relationship between different tables and views in database.

## Types of Keys in SQL Server :

There are several types of keys are used in SQL Server Database which are as-

![What are key in SQL Server? How many types of keys in SQL Server and also define with example?](https://answers.mindstick.com/questionanswer/14a36942-60f1-414e-b18d-3840b4773e75/images/837ed5d4-65af-4771-8c77-e58d5ce82b85.png)\

\

**Super Key :** A super key is a single or group of keys that can used to uniquely identify rows in a table.

**Ex-** primary key, Alternate key and Unique are subset of super key.

**Candidate Key :** It is a single key or group of multiple keys that can identify uniquely of rows in a table.

**Ex-** EmpId, License_Number and Passport_number of **Employee** table is a Candidate key.

**Primary key :** A Primary key is a Candidate key that selected by Database administrator to uniquely identify the row in database table. There can be only one Candidate key become a primary key to retrieve the data from table.

**Ex-** EmpId of Employee table is a primary key. It also a Candidate key.

**Alternate Key :** Alternate key are those Candidate keys which are not selected as primary key.

**Ex-** License_Number and Passport_number is Alternate key of table Employee

**Foreign Key :** Foreign key is a key of table that are defined as primary key in its parent table. Or primary key of a parent table is a foreign key of its child table.

**Ex-** EmpId of **Salary** table is a foreign key.

**Composite Key :** A Composite key is a primary key or candidate key that consist more than one attribute(column name) of a table.

**Ex-** EmpId and SalaryDate of **Salary** table is composite key.

**Unique Key :** A unique key is a set of one or more than one field or column of a table that uniquely identify a record in a database table.

**Ex-** License_Number and Passport_number of **Employee** Table is a Unique key.


---

Original Source: https://answers.mindstick.com/qa/93944/what-are-key-in-sql-server-how-many-types-of-keys-in-sql-server-and-also-define-with-example

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
