In previous chapter, we had a good discussion on “Data Integrity” and in this chapter “Types of Keys”, we are going to discuss Keys and their types in SQL Server. Lets start this topic by defining keys”.
What is Key?
Keys are fields in a table which participate in below activities in RDBMS systems:
- To create relationships between two tables.
- To maintain uniqueness in a table.
- To keep consistent and valid data in database.
- Might help in fast data retrieval by facilitating indexes on column(s).
SQL Server supports various types of keys, which are listed below:
- Candidate Key
- Primary Key
- Unique Key
- Alternate Key
- Composite Key
- Super Key
- Foreign Key
Before discussing each type in brief, have a look on the below image used as an an example to define types of keys.
Lets discuss each type in detail:
Candidate key is a … More