One of my regular blog reader Mr.Jithin requested me to explain about the different types of keys in sql server. Let’s come have a look into this topic.
The different types of Keys in sql server are,
- A candidate key acts as a unique key. A unique key can be a Primary key. A candidate key can be a single column or combination of columns. Multiple candidate keys are allowed in a table.
- Primary Key
- To uniquely identify a row, Primary key is used.
- A table allows only one Primary key
- A Primary key can be a single column or combination of columns.
- Foreign Key
- A foreign key in a table is a key which refer another table’s primary key . A primary key can be referred by multiple foreign keys from other tables. It is not required for a primary key to be the reference of any foreign keys. The interesting part is that a foreign key can refer back to the same table but to a different column. This kind of foreign key is known as “self-referencing foreign key”.